diff --git a/compiler2/Type_codegen.cc b/compiler2/Type_codegen.cc index f6225b8938ae4008a5f3a280742d673a8607ded2..530c2e83763ab6accb15e25de12f11b6e77f3c62 100644 --- a/compiler2/Type_codegen.cc +++ b/compiler2/Type_codegen.cc @@ -2472,10 +2472,10 @@ void Type::generate_code_ispresentbound(expression_struct *expr, const string& tmp_id = module->get_temporary_id(); const char *tmp_id_str = tmp_id.c_str(); expr->expr = mputprintf(expr->expr, - "const %s%s& %s = %s.%s();\n", + "const %s%s& %s = %s.%s%s();\n", next_t->get_genname_value(module).c_str(), is_template?"_template":"", tmp_id_str, tmp_generalid_str, - id.get_name().c_str()); + t->typetype == T_ANYTYPE ? "AT_" : "", id.get_name().c_str()); expr->expr = mputprintf(expr->expr, "%s = %s.%s(%s);\n", global_id.c_str(), diff --git a/regression_test/ispresent/IsPresent_Test.ttcn b/regression_test/ispresent/IsPresent_Test.ttcn index 41a4a7f1c3425919a3a0e441e20cab6450ad531e..60fbb5bfae8145f52d07c53d3bfa70198b858f25 100644 --- a/regression_test/ispresent/IsPresent_Test.ttcn +++ b/regression_test/ispresent/IsPresent_Test.ttcn @@ -838,6 +838,19 @@ type record of MyRec2 MyRecOf if(ispresent(t_i(1,2*vl_i))) {setverdict(pass)} else {setverdict(fail)}; //if(ispresent(t_i(1,2/vl_j))) {setverdict(pass)} else {setverdict(fail)}; //DTE } + + // Test case for: + // Bug 495128 - Incorrect code generated for anytype field reference in ispresent clause + // The 'ispresent' clauses in this test caused C++ compilation errors, because + // 'x.MyRecord()' was generated instead of 'x.AT_MyRecord()', when accessing the anytype field + testcase tc_anytype_field() runs on MTC_CT { + var anytype x; + x.MyRecord := { i := 1, x := omit, c := "a" }; + if (ispresent(x.MyRecord.i)) { setverdict(pass); } + else { setverdict(fail, "field i should be present"); } + if (not ispresent(x.MyRecord.x)) { setverdict(pass); } + else { setverdict(fail, "field x should not be present"); } + } control { @@ -929,7 +942,10 @@ type record of MyRec2 MyRecOf //execute(tc_runtimeDivisionByZero()); //expected DTE //execute(tc_compilationErrorDivisionByZero()); ok!? execute(tc_runtimeExprEval()); - + execute(tc_anytype_field()); } }//module +with { + extension "anytype MyRecord"; +}