diff --git a/compiler2/union.c b/compiler2/union.c index d71ec321a324dbfb70fe1cd8ef40480b8c38fd87..a61dec8f90223d10fe39fe39ec637f2838f3ee2a 100644 --- a/compiler2/union.c +++ b/compiler2/union.c @@ -2307,7 +2307,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output) " }\n" " return ret_val;\n"); if (!sdef->jsonAsValue) { - src = mputprintf(src, + src = mputstr(src, " }\n" " else {\n" // if there is no 'as value' set in the type descriptor " size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n" @@ -2324,9 +2324,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output) " if (JSON_TOKEN_NAME != j_token) {\n" " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_NAME_TOKEN_ERROR);\n" " return JSON_ERROR_FATAL;\n" - " } else {\n" - " union_selection = %s;\n " - , unbound_value); + " } else {\n"); for (i = 0; i < sdef->nElements; ++i) { src = mputprintf(src, "if (%d == name_len && 0 == strncmp(fld_name, \"%s\", name_len)) {\n" diff --git a/regression_test/json/Functions.ttcn b/regression_test/json/Functions.ttcn index 7ca9708af6b7e4c94211347966822c1bc0b1a241..9bf007dd4a85500a409ea5583ea7612535c37e6a 100644 --- a/regression_test/json/Functions.ttcn +++ b/regression_test/json/Functions.ttcn @@ -279,6 +279,9 @@ external function f_dec_R(in octetstring x) return R external function f_dec_A(in octetstring x) return A with { extension "prototype(convert)"; extension "decode(JSON)"; } +external function f_dec_A_fast(in octetstring x, out A y) + with { extension "prototype(fast)"; extension "decode(JSON)"; } + external function f_dec_ER(in octetstring x) return EmptyRec with { extension "prototype(convert)"; extension "decode(JSON)"; } diff --git a/regression_test/json/Testcases.ttcn b/regression_test/json/Testcases.ttcn index 40b5d132b0ef386561830fe3897fa45587754646..ba297a29a0e42f11875f1a97d33f4eb41aa168f7 100644 --- a/regression_test/json/Testcases.ttcn +++ b/regression_test/json/Testcases.ttcn @@ -506,6 +506,9 @@ testcase tc_union2() runs on MTC{ var octetstring os := char2oct("{\"f\":\"infinity\"}"); f_check_encoding(encoded:= f_enc_A(myunion), expected := os) f_bool2verdict(match(f_dec_A(f_enc_A(myunion)), myunion)); + var A myunion2 := { b := false }; + f_dec_A_fast(f_enc_A(myunion), myunion2); + f_bool2verdict(match(myunion2, myunion)); } testcase tc_union_false() runs on MTC{