ETSI's Bug Tracker - Part 01: TTCN-3 Core Language
View Issue Details

ID | Project | Category | View Status | Date Submitted | Last Update
0007437 | Part 01: TTCN-3 Core Language | New Feature | public | 31-05-2016 13:07 | 14-11-2016 16:23

Reporter | Jacob Wieland - Spirent |
Assigned To | KristÃ³f Szabados |
Priority | normal | Severity | minor | Reproducibility | have not tried
Status | closed | Resolution | no change required |
Platform |  | OS |  | OS Version |
Product Version | v4.8.1 (published 2016-07) |
Target Version | v4.9.1 (published 2017-05) | Fixed in Version |  |
Clause Reference(s) | 6.2.5, C.3.2
Source (company - Author) | Spirent - Jacob Wieland

Summary | 0007437: It should be possible to assign the variant of a union to a variable and use such variant values for union operations

Description

Consider the following use case:
type union U { ... }
type record of U RU;
template RU containsV := { *, { V := X }, *}
At the moment, there is no easy way to access X or to write a function which
gets the list and the variant V and produces the union value which has variant V.
What can be envisioned could be something like this:
function getElementOfVariant(RU list, U.variant v) return U {
for (var integer i := 0; i < lengthof(list); i:= i+1) {
if (ischosen(list[i], v)) {
return list[i];
}
}
}
Thus, U.variant would be an implicit enumerated type containing the enumerated values that are the variant names of the union type while the ischosen operation would be overloaded so that it can always take a pair of U and U.variant as actual parameters and check, whether the given variant is the one chosen in the union value/template. The ischosen would get the two items as separate parameters because both actual parameters can be arbitrarily complex dotted notations and using dot-notation to combine them would be ambiguous.
The construct u.variant (where u is a union value of type U) could be used to actually get the variant from a union value (so u.variant is always of type U.variant iff u is of union type U).
All other restrictions of enumerated types would apply to the variant type of a union type.

Steps To Reproduce |
Additional Information | All this can be done already by programming it explicitly, but needs to be done for every union type anew. The proposed feature would give the user a generic solution for this problem.
Tags | No tags attached.
Relationships |
Attached Files |

Issue History
Date Modified | Username | Field | Change
31-05-2016 13:07 | Jacob Wieland - Spirent | New Issue |
18-07-2016 10:29 | Jens Grabowski | Assigned To | => KristÃ³f Szabados
18-07-2016 10:29 | Jens Grabowski | Status | new => assigned
16-08-2016 14:45 | Jacob Wieland - Spirent | Note Added: 0014110 |
17-08-2016 11:25 | Jacob Wieland - Spirent | Project | TTCN-3 Change Requests => Part 01: TTCN-3 Core Language
17-08-2016 11:26 | Jacob Wieland - Spirent | Product Version | => v4.8.1 (published 2016-07)
17-08-2016 11:26 | Jacob Wieland - Spirent | Target Version | => v4.9.1 (published 2017-05)
13-11-2016 16:50 | KristÃ³f Szabados | Note Added: 0014224 |
14-11-2016 03:45 | Jacob Wieland - Spirent | Note Added: 0014225 |
14-11-2016 03:46 | Jacob Wieland - Spirent | Note Added: 0014226 |
14-11-2016 16:23 | Jens Grabowski | Note Added: 0014232 |
14-11-2016 16:23 | Jens Grabowski | Status | assigned => closed
14-11-2016 16:23 | Jens Grabowski | Resolution | open => no change required

Notes

(0014110)
Jacob Wieland - Spirent
16-08-2016 14:45

Because the .variant would clash with the attribute retrieval operation, we propose to use
<union_type>.enumerated to signify the enumerated type of the union variants
and
<union_value>.present to evaluate to the enumerated value of the present variant
The following rule applies:
If u is of union type U, then u.present is of type U.enumerated.
For the ischosen operation with two arguments, the restriction must be that the first argument must be a value of a union type U and the second argument must be of type U.enumerated.

(0014224)
KristÃ³f Szabados
13-11-2016 16:50

Can't the initial task be solved by something like this:
function getElementOfVariant(RU list, template U v) return U {
for (var integer i := 0; i < lengthof(list); i:= i+1) {
if (match(list[i],v)) {
return list[i];
}
}
return list[0];
}
...
var RU containsV := { { field1 := 1 }, {field2 := "something"}};
var U temp := getElementOfVariant(containsV, {field1 := ?});
log("result: ", temp);
temp := getElementOfVariant(containsV, {field2 := ?});
log("result: ", temp);
Where U is a union of an integer and charstring field

(0014225)
Jacob Wieland - Spirent
14-11-2016 03:45

true, also with the new template with out parameters, it would be even easier to get access to the actual value: if (match(l,{*,{field:=? -> v},*})) { /* do something with v */ }

(0014226)
Jacob Wieland - Spirent
14-11-2016 03:46

so, in essence, I propose to drop this issue

(0014232)
Jens Grabowski
14-11-2016 16:23

See discussion.