Delphi inner scoping is undefined. Please Embarcadero/Idera, come up with a formal language definition for Delphi

  

[WayBack] Hi there, this is pure curiosity only; but this compiler behaviour seems odd to me. What do you think?… – Agustin Ortu – Google+
The problems start when you prefix the outer class which you have to when using inner consts ([WayBack] Oh nice. Feel free to QP. Fails at least in Delphi XE8. … – Jeroen Wiert Pluimers – Google+).
The big problem in both cases is a formal language specification. The lack of a formal language specification makes it very hard to predict the effect of use cases or generate them for testing.
So this post is yet another request: Please Embarcadero/Idera, come up with a formal language definition for Delphi.

unit ParentUnit;

interface

type
TParent = class
// section can be strict protected, protected, public, published or nothing
const
InitialBooleanValue = False;
InitialIntegerValue = -1;
end;

implementation

end.

The below the ChildUnit doesn’t compile at all:

unit ChildUnit;

interface

uses
ParentUnit;

type
TChild = class(TParent)
// section can be strict protected, protected, public, published or nothing
const
// Initial and final values need to be different to test the behaviour
FinalBooleanValue = not InitialBooleanValue;
FinalIntegerValue = InitialIntegerValue + 1;
//[dcc32 Error] ChildUnit.pas(13): E2003 Undeclared identifier: ‘InitialBooleanValue’
//[dcc32 Error] ChildUnit.pas(14): E2003 Undeclared identifier: ‘InitialIntegerValue’
//[dcc32 Error] ChildUnit.pas(14): E2026 Constant expression expected
end;

implementation

end.

This does compile but requires the parent class specified explicitly:

unit ChildUnit;

interface

uses
ParentUnit;

type
TChild = class(TParent)
// section can be strict protected, protected, public, published or nothing
const
// Initial and final values need to be different to test the behaviour
FinalBooleanValue = not TParent.InitialBooleanValue;
FinalIntegerValue = TParent.InitialIntegerValue + 1;
end;

implementation

end.

Back to the usage of interfaces:
Code example [WayBack] Program2.pas · GitHub:

 
–jeroenFiled under: Delphi, Development, Software Development

Comments are closed.