bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Function/Method references wrongly interpreted as calls #444

Open HurryStarfish opened 5 years ago

HurryStarfish commented 5 years ago

Bug Report

SuperStrict
Framework BRL.StandardIO

Type T
    Method M:Int() Return 1 End Method
    Function F:Int() Return 2 End Function
End Type

Function Test:Int()
    Local o:T = New T
    'Return T.F     ' "Unable to convert from Int() to Int"
    'Return T.M     ' "Internal Error in TCTranslator.TransFunc"
    'Return o.F     ' "Unable to convert from Int() to Int"
    'Return o.M     ' compiles and runs
    'Return New T.M ' compiles and runs
    'Return New T.F ' compiles and runs
End Function

Print Test()

Expected Behavior

Any of the above Return statements, when uncommented, should result in a compile error, since function/method names not followed by parentheses may only be interpreted as calls when they are statements, not when they are expressions. This should be "Unable to convert from Int() to Int" for the lines including .F; possibly a different message for the lines including .M, as it is not currently allowed to treat a method as a value (or, in the case of Return T.M, to reference it from its type name instead of an object).

Actual Behavior

see the code comments

GWRon commented 1 year ago

Is the issue still valid?

GWRon commented 1 year ago

Update to this issue: Only the last two ones are still wrongly treated as "method" or "function" call.

Function Test:Int()
    Local o:T = New T
    'Return T.F     ' "Unable to convert from Int() to Int"
    'Return T.M     ' "Method 'M' cannot be accessed from here."
    'Return o.F     ' "Unable to convert from Int() to Int"
    'Return o.M     ' "Method cannot be used as a function pointer"
    'Return New T.M ' compiles and runs -> 1
    'Return New T.F ' compiles and runs -> 2
End Function