microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
748 stars 244 forks source link

JsonObject remains uninitialized #6801

Open LNitzsche opened 3 years ago

LNitzsche commented 3 years ago

1. Describe the bug A return parameter of type JsonObject will be return as uninitialized if not explicitly set.

In BC versions up to 18 you could instantiate a return parameter of any type in a procedure and the return value was valid, even if not explicitly assigned. (see code below)

2. To Reproduce

Take the function described below and check the return value. In BC 19 the return value is uninitialized.

procedure newJson() newObj: JsonObject begin end;

In versions up to BC version 18 this is a legal function, because newObj is instantiated as a local variable and contains a valid empty JSON object. This valid object will be given back to the caller. There is no need to make any assignment to jobj in the procedure body.

jsonvar := newJson() ; // will always initialize jsonvar with a new empty JsonObject jsonvar.Add('Testproperty', 42); // should work

3. Expected behavior

I would expect to have an empty JsonObject in jsonvar after the call.

4. Actual behavior

After the call jsonvar := newJson() ;
the debugger shows the content of jsonvar as "uninitialized" and jsonvar.Add('Testproperty', 42); // rises a runtime error

5. Versions:

This version and below does not have this error: Version: W1 18.0 (Platform 18.0.22893.23773 + Application 18.0.23013.23795)

Final Checklist

nicolassaleron commented 1 year ago

The bug is still there in BC 21.4 Is there any plan to fix it?

apoyas commented 2 months ago

BC24 - the bug is still there :(