X-Sharp / XSharpPublic

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

[VFP] Problem subscribing to events when /undeclared+ is on #1620

Open cpyrgas opened 1 month ago

cpyrgas commented 1 month ago

In the following code, when undeclared is on, the references to method myhandler() and the function myhandler_func() used for subscribing to the event are seen as undeclared memvars, resulting to runtime errors about them not being defined.

Not sure if this can be distinguished by the compiler.

#pragma options (memvar,on)
#pragma options (undeclared,on)

#pragma options (fox2,off)
//#pragma options (fox2,on) // does not make a difference

CLASS TestClass
    EVENT myEvent AS EventHandler
    CONSTRUCTOR()
        SELF:myEvent += EventHandler{ SELF , @myhandler() } // works OK
        SELF:myEvent += SELF:myhandler // works OK
        SELF:myEvent += myhandler // warning XS9073: Variable 'myhandler' has not been declared. Assuming this is a FIELD or a MEMVAR.

        SELF:myEvent += EventHandler{ NULL , @myhandler_func() } // warning XS9073: Variable 'myhandler_func' has not been declared. Assuming this is a FIELD or a MEMVAR.
        SELF:myEvent += myhandler_func // warning XS9073: Variable 'myhandler_func' has not been declared. Assuming this is a FIELD or a MEMVAR.

        SELF:myEvent(NULL,NULL)
    RETURN

    METHOD myhandler(sender AS OBJECT , e AS EventArgs) AS VOID
        ? "invoked"
END CLASS

    FUNCTION myhandler_func(sender AS OBJECT , e AS EventArgs) AS VOID
        ? "invoked"

FUNCTION Start( ) AS VOID
    TestClass{}
RETURN
RobertvanderHulst commented 1 month ago

This may be difficult to detect. I'll see what I can do.