Typed parameters in codeblocks
Posted: Thu May 07, 2020 6:44 pm
I get an error while trying to compile a static codeblock with typed arguments:
Error XS9057. Typed parameters in codeblocks are not supported by the runtime.
But in fact CAVO supported typed arguments in codeblocks pretty fine. There was just a warning, which may be disabled without consequences. And there are lots of advantages when using typed arguments: compiler really does a compile-time check for any type compatibility, allows you to make an early-bound call, etc. It's just the intellisence which doesn't work on those variables, but everything concerning compiling and linking works just as it should.
For instance, such a code works in VO:
But this code refuses to compile in X#.
Error XS9057. Typed parameters in codeblocks are not supported by the runtime.
But in fact CAVO supported typed arguments in codeblocks pretty fine. There was just a warning, which may be disabled without consequences. And there are lots of advantages when using typed arguments: compiler really does a compile-time check for any type compatibility, allows you to make an early-bound call, etc. It's just the intellisence which doesn't work on those variables, but everything concerning compiling and linking works just as it should.
For instance, such a code works in VO:
Code: Select all
CLASS Test
~"ONLYEARLY+"
DECLARE METHOD EarlyMethod
~"ONLYEARLY-"
METHOD EarlyMethod(nArg AS INT) AS VOID PASCAL CLASS Test
? nArg
RETURN
FUNCTION doTest() AS VOID PASCAL
LOCAL oTest AS Test
LOCAL cbGood, cbBad AS CODEBLOCK
oTest := Test{}
// this compiles with no errors (with a suppressible warning)
cbGood := {|oTestClass AS Test, nParam AS INT| oTestClass:EarlyMethod(nParam)}
Eval(cbGood, oTest, 5) // prints 5 as expected
// and that will not compile due to type incompatibilty of the argument:
cbBad := {|oTestClass AS Test| oTestClass:EarlyMethod("string")}
RETURN