Typed parameters in codeblocks

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
Serggio
Posts: 46
Joined: Sun May 14, 2017 5:03 pm
Location: Ukraine

Typed parameters in codeblocks

Post by Serggio »

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:

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
But this code refuses to compile in X#.
Serggio
Posts: 46
Joined: Sun May 14, 2017 5:03 pm
Location: Ukraine

Typed parameters in codeblocks

Post by Serggio »

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.
User avatar
robert
Posts: 4551
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Typed parameters in codeblocks

Post by robert »

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...)

Code: Select all

 cbGood := {|uTestClass , uParam | 
   LOCAL oTestClass := uTestClass as Test 
   LOCAL nParam := uParam as INT
   oTestClass:EarlyMethod(nParam) 
   RETURN NIL 
   }

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4551
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Typed parameters in codeblocks

Post by robert »

Serrgio,

This works:

Code: Select all

	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
robert@xsharp.eu
Serggio
Posts: 46
Joined: Sun May 14, 2017 5:03 pm
Location: Ukraine

Typed parameters in codeblocks

Post by Serggio »

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!
User avatar
robert
Posts: 4551
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Typed parameters in codeblocks

Post by robert »

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

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply