Details
-
Story
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
Security Level: Users (General product issues)
-
8
-
UNDECIDED
-
Green Sprint 105, Green Sprint 106, Green Sprint 107, Green Sprint 108
Description
Variant is new data type equivalent to Object type in Java - i.e. can be assigned with any value type - integer/string/map/list/…etc.. No type checking is performed and also the assignment is only one-way - anything to variant. When assigning variant to any other type or when variant’s value to be used in any statement, it has to be first cast into the proper type - e.g. integer or string. Assigning variant to variant works as expected.
You can look at variant as a container into which you put your data (at which point the data loose its type) and can be taken later, but before it can be used in CTL, the type has to be returned (cast function will be introduced by CLO-18045).
Example:
variant myvariant; variant myvariant2; integer myint = 10; string mystring; myvariant = myint; //myvariant now containst 10 myvariant2 = myvariant; //myvariant2 now contains 10; myvariant2 = “ABC”; //myvariant2 now contains “ABC”; myint = myvariant; //this raises error, type of myint is not compatible with type of myvariant
Variant can be treated as list or map - i.e. array access can be performed through [ ] operator. For this to be successful the variant has, at the moment, contain value of type list of map. One way of doing this is to “initialize” variant with empty map or list first:
variant myvariant; myvariant = {}; //now contains an empty map myvariant[“first-key”] = “value”; //new key-value pair created myvariant[“second-key”] = {}; //new empty map created under second-key myvariant[“second-key”][“level-2-key”] = “value”; //new key-value pair created in map, stored under “second-key” in myvariant
Variant data type can be used as function argument type and function return type.
The behavior of list/map implementation has been changed.
- Map - there is now difference between KEY mapped to NULL value and KEY not existing in MAP. Accessing non existing KEY now leads to a runtime error. Also there is no more magic when referencing multiple “embedded” lists or maps - empty MAP or LIST does not get automatically created any more - myvariant[“nonexistent”][“somekey”] previsously led to creation of empty MAP under “nonexistent” key first (so leve-2 map could contain new “somekey” key). Now, the “nonexistent” key has to be assigned empty MAP (using empty MAP literal) first.
- List - automatic extension of lists when assigning value to index outside of current List length is no longer supported. Using append() function is recommended now. Attempt to assign to non-existing index leads to runtime error.
Attachments
Issue Links
1.
|
Fix CTL debugging |
|
Closed | Milan Krivanek (Inactive) |
|
|||||||
2.
|
Port changes |
|
Closed | Roland Botka | ||||||||
3.
|
Add automated tests |
|
Closed | Martin Predny (Inactive) | ||||||||
4.
|
Update syntax highlighter and content assist |
|
Closed | Martin Predny (Inactive) | ||||||||
5.
|
Update documentation |
|
Closed | Martin Predny (Inactive) | ||||||||
6.
|
Test CTL debugging of variant after porting the changes |
|
Closed | Martin Slama | ||||||||
7.
|
Fix variant CTL debugging |
|
Closed | Lukas Adamek (Inactive) |