Community
Participate
Working Groups
As part of the nullability language changes, we started allowing handlers to have constructors. Unfortunately we're not allowing people to write a body for their constructors. handler handleme private constructor(); // Should be invalid, but no error. constructor( i int out ); // Should be invalid, but no error. constructor( s string in ) // Should be valid. x = foo(); SysLib.writeStdout( s ); end x int; function foo() returns( int ) return( 1 ); end end
I have released some support for this. You can now define statements, and they are validated and generated into the IR. However, the resolution code needs to be updated to support invoking a constructor from within a constructor. EX: Handler hand1 constructor() .... end constructor(f1 int) this(); ... end end Also, we need to define what rules there are for invoking a constructor in this manner. Java, for instance, only lets you invoke a constructor using "this()" if you are on the first line of a constructor.
I have fixed the original problem with this. You can now specify statements in the constructors. However, the code can still not handle resolution to constructors via the "this" syntax. For example: Handler myHandler field1 int; field2 string; constructor(p1 int) field1 = p1; end constructor(p1 int, p2 string) this(p1); // this resolution fails in binding and in the IRs field2 = p2; end end Also, we have not yet defined what restrictions may exist for invoking constructors within constructors. In Java, for instance, a constructor invocation must be the first statement inside a constructor. I am leaving this bug open until the resolution problem is fixed and any validation that is required is written.
This work has been completed
Do we have restrictions on invoking constructors within constructors, such as the one in Java?
Yes, for now I have added valdiation checks so that the syntax: this(...) to invoke a constructor can only be used as the first statement of a constructor.
Verified.