Tuesday, 1 March 2016

Compiler diagnoses attempts to store objects in containers AX7

In previous incarnations of the X++ compiler, it was possible to store object references into containers, even though this would fail at runtime. This is no longer possible. When the compiler sees an attempt to store an object reference into a container:
container c = [new Query()];
It will issue the error message:
Instances of type 'Query' cannot be added to a container.
If the type of the element that is added to the container is anytype the compiler can’t make the determination of whether or not the value is a reference type. The compiler will allow this under the assumption that the user knows what they’re doing. The compiler won’t diagnose the following code as erroneous:
anytype a = new Query();
        container c = [a];
but an error will be thrown at runtime.

No comments:

Post a Comment