X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
112 stars 38 forks source link

GrandParent class constructor invisibility in XSharp 2.7 #532

Closed leon-ts closed 3 years ago

leon-ts commented 3 years ago

An error occurs when compiling the following example:

CLASS ClassA
    CONSTRUCTOR( cValue )
        RETURN
END CLASS

CLASS ClassB INHERIT ClassA
END CLASS

CLASS ClassC INHERIT ClassB
    CONSTRUCTOR( cValue )
        SUPER(cValue)
        RETURN
END CLASS

Error: XS1501 No overload for method '.ctor' takes 1 arguments

This is an artificially created example to demonstrate the problem. The original code where I encountered a compilation error uses VOGUI:

CLASS CitDialogWindow INHERIT DialogWindow
    CONSTRUCTOR(oOwner, xResourceID, lModal) 
        SUPER(oOwner, xResourceID, lModal)
                // some code ...
        RETURN
END CLASS

CLASS CitBasePageDialogWindow INHERIT CitDialogWindow 
    // no constructor
END CLASS

CLASS SomePageDialogWindow INHERIT CitBasePageDialogWindow 
    CONSTRUCTOR(oOwner, xResourceID, lModal) 
        SUPER(oOwner, xResourceID, lModal)
                // some code ...
        RETURN
END CLASS

XSharp 2.6, like VO, has no problem compiling code like this.

leon-ts commented 3 years ago

/vo16 option disabled If I enable the /vo16 option then no error occurs.

RobertvanderHulst commented 3 years ago

Leonid,

We had to change this because sometimes people were accidentally calling methods in a parent constructor, when they forgot to include "new" arguments defined in the child level, leading to unwanted side effects. This is the change that was documented in the second bullet in the what's new: Fixed a problem with calling a parent constructor in a class hierarchy where a parent level was being skipped and the constructor for the grandparent was called instead. In this example calling the grandparent constructor has no side effects, but for example if you had fields in the CitBasePageDialogWindow class that are declared with an initializer:

CLASS CitBasePageDialogWindow INHERIT CitDialogWindow 
    PROTECT IShouldBeInitialized := 42 AS LONG
....
END CLASS

Then you would see that the field `IShouldBeInitialized` is not initialized with the previous build.

Robert

leon-ts commented 3 years ago

Robert,

I carefully read whatsnew before installing version 2.7. And when I found out that the code that compiled in 2.6 stopped compiling, I thought, then I remembered this point and thought that something was broken. But when you have now clarified in more detail the purpose of this fix, then I completely agree that the new behavior of the compiler is preferable.

Thanks!

Best regards, Leonid