Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

Typed parameters in codeblocks 07 May 2020 20:44 #14436

  • Serggio
  • Serggio's Avatar
  • Topic Author


  • Posts: 45
  • 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:
    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

    But this code refuses to compile in X#.

    Please Log in or Create an account to join the conversation.

    Typed parameters in codeblocks 07 May 2020 22:10 #14437

    • Serggio
    • Serggio's Avatar
    • Topic Author


  • Posts: 45
  • Maybe there's a simple way to cast somehow a lambda-expression to a static codeblock? They seem to be of the same nature. That would solve the problem either.

    Please Log in or Create an account to join the conversation.

    Last edit: by Serggio.

    Typed parameters in codeblocks 07 May 2020 23:26 #14439

    • robert
    • robert's Avatar


  • Posts: 3447
  • Serggio,
    This is new to me.
    I did not know that VO allowed this (and I have worked on VO for a few years ...).
    I don't think this was intentional.
    I'll have to study this and discuss this with the guys.

    But since we have multi line codeblocks, this should work (but it does not...)
    cbGood := {|uTestClass , uParam | 
       LOCAL oTestClass := uTestClass as Test 
       LOCAL nParam := uParam as INT
       oTestClass:EarlyMethod(nParam) 
       RETURN NIL 
       }


    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Typed parameters in codeblocks 07 May 2020 23:31 #14440

    • robert
    • robert's Avatar


  • Posts: 3447
  • Serrgio,

    This works:
    cbGood := {|oTestClass , nParam |  ((Test) oTestClass ):EarlyMethod( (int) nParam ) }

    Maybe we can tell the compiler to produce something like this when you declare typed parameters for a codeblock.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    Typed parameters in codeblocks 08 May 2020 00:08 #14442

    • Serggio
    • Serggio's Avatar
    • Topic Author


  • Posts: 45
  • Robert,
    That's a good workaround! Thank you!
    And if you make it somehow behind the scenes so that the original syntax keeps intact, that would be superb!

    Please Log in or Create an account to join the conversation.

    Typed parameters in codeblocks 08 May 2020 08:36 #14445

    • robert
    • robert's Avatar


  • Posts: 3447
  • Serggio,
    I have created a ticket for this:
    github.com/X-Sharp/XSharpPublic/issues/388

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1