Uploaded image for project: 'CloverDX'
  1. CloverDX
  2. CLO-18041

Variant data type



    • Story
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • rel-5-6-0
    • None
    • Security Level: Users (General product issues)
    • 8
    • Green Sprint 105, Green Sprint 106, Green Sprint 107, Green Sprint 108


      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).


      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.


        Issue Links



              slamam Martin Slama
              krivanekm Milan Krivanek (Inactive)
              0 Vote for this issue
              2 Start watching this issue



                Time Tracking

                  Original Estimate - Not Specified
                  Not Specified
                  Remaining Estimate - 0 minutes
                  Time Spent - 30 minutes