Community
Participate
Working Groups
Here is the .egl file package a; delegate jingDelegate(i int) end // basic program // program Hello type BasicProgram {} function main() sysLib.writeStdOUt("abc"); a jingDelegate[] = new jingDelegate[1]; a[1] = function1; a[1](4); end function function1(i int) i += 5; sysLib.writeStdout("function1 is delegate, i is " + i); end end It gens and compiles in java, but when you run it, you will get egl.lang.InvalidArgumentException because it's trying to call delegate.newInstances(), and it does not have that method defined.
This is a blocking issue for EUnit framework, as I use delegate array in the framework.
This changed as part of the initialization and nullability language changes. Any type that doesn't have a default (no argument) constructor, such as a delegate, must be declared nullable. The same goes for arrays of delegates. There should be an error on the declaration saying that it should be nullable. The declaration should look like this: a jingDelegate?[] = new jingDelegate?[1];
while I changed my generated code to use nullable ? to by pass this issue for now. I very much question the way this is designed, as it makes the coding a lot more complex when user uses array of objects (delegates, externalTypes, etc..), especially for delegates, And I can see another issue with this design. consider the following: I have a function defined as function myFunc(a jingDelegate[]) x jingDelegate = somedelegate; a.append(x); end In order for someone to call this function. they HAVE TO declare a variable v jingDelegate[] = [a, b, c]; (by the way, this doesn't work yet, there is another defect open on it) user HAS TO initialize every single element at the declaration time. what if the logic is to have the function initialize all of the elements.
while I changed my generated code to use nullable ? to by pass this issue for now. I very much question the way this is designed, as it makes the coding a lot harder when user uses array of objects (delegates, externalTypes, etc..), And I can see other issues with this design. - especially for delegates, how do I make to have an empty constructor? - consider the following: I have a function defined as function myFunc(a jingDelegate[]) x jingDelegate = somedelegate; a.append(x); end In order for someone to call this function. they HAVE TO declare a variable v jingDelegate[] = [a, b, c]; (by the way, this doesn't work yet, there is another defect open on it) user HAS TO initialize every single element at the declaration time. what if the logic is to have the function initialize some or all of the elements
[I changed the component from MOF Model to Compiler since this is a validation issue.] Jing, why do you say this design makes coding a lot harder? As I understand it, the only new thing you have to do is add some question marks. And after this validation defect is fixed, you'll get a red X telling you where the question marks are needed. > - especially for delegates, how do I make to have an empty constructor? You can't. It doesn't make sense for a delegate to have a constructor. A delegate is sort of a mini-interface, like an interface with just one function. So it's an abstract thing that can't be instantiated. > - consider the following: Your example function is not really valid. The parameter's type should be jingDelegate?[] not jingDelegate[]. That means the elements of the array can be uninitialized because they'll default to null.
I have updated DelegateBinding so that delegates are not instantiable
This high severity defect was fixed several weeks ago, so I am closing.