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

No compiler error when assigning OBJECT to typed var, with /vo7+ enabled #1471

Open cpyrgas opened 4 months ago

cpyrgas commented 4 months ago

When /vo7 is disabled, the following code results to a compiler error for all assignments from OBJECT to a typed var. VO does the same.

When /vo7 is enabled, only the LOGIC,DATE,Char->OBJECT assignments produce a compiler error.

FUNCTION Start() AS VOID
LOCAL o := NULL AS OBJECT

// following report an error no matter the state of /vo7
LOCAL l := o AS LOGIC // error XS0266: Cannot implicitly convert type 'object' to 'int'
LOCAL d := o AS DATE  // error XS0266
LOCAL c := o AS Char  // error XS0266

// following report error only when /vo7 is enabled
LOCAL n := o AS INT
LOCAL dw := o AS DWORD
LOCAL b := o AS BYTE
LOCAL s := o AS STRING
LOCAL sym := o AS SYMBOL
LOCAL p := o AS PTR
LOCAL obj := o AS TestClass

CLASS TestClass
END CLASS
cpyrgas commented 4 months ago

In the final 2.20 version, now none of the lines report an error, but also do not throw a runtime error either (anymore), locals get their default value. Only the NULL->PTR assignment does throw an exception.

Still the behavior is not right, but since there's existing code depending on it, let's put this on hold.