ASTYPE problem
Based on the documentation sample for ASTYPE (I will correct it):
FUNCTION Start() AS VOID
Test("abc")
FUNCTION Test(oVar AS OBJECT) AS VOID
LOCAL oChild := oVar ASTYPE STRING // error XS0266: Cannot implicitly convert type 'object' to 'string'
this reports error XS0266: Cannot implicitly convert type 'object' to 'string', which is a bogus error message.
I think also the sample code is incorrect, as the LOCAL is not given explicitly a type with an AS clause, so I think the compiler should report a "Type expected" error in core dialect (or any dialect if /vo15 is not enabled).
The correct working code would be
LOCAL oChild := oVar ASTYPE STRING AS STRING
Truth is this looks a bit redundant, so maybe it was on purpose that this syntax
LOCAL oChild := oVar ASTYPE STRING
is also supposed to strongly type oVar AS STRING, as if the "AS" clause was actually supplied?
If that's the case, then it's currently working as it's reporting a compiler error as mentioned above.
Robert, of course this is not high priority :)
I do not think we should allow
LOCAL oChild := oVar ASTYPE STRING
to make oChild string.
This will work:
VAR oChild := oVar ASTYPE STRING
To clarify
oVar ASTYPE STRING
is an expression And the local rule (simplified) is this
LOCAL <varName> [:= <expression>] [AS <type>]
Robert, I agree we should not allow LOCAL oChild := oVar ASTYPE STRING to make oChild STRING.
So this (with the LOCAL syntax) should instead report an error that the type is missing (core dialect), do you agree?
The error XS0266: Cannot implicitly convert type 'object' to 'string' is bogus.
Yes, that error is not correct.