diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc index 95247f4098419b18326d759bb080a5caed9d8b7a..ac5a6fd72d9cd5ad821c610325c8fe6daa97f710 100644 --- a/compiler2/Type_chk.cc +++ b/compiler2/Type_chk.cc @@ -4355,7 +4355,7 @@ bool Type::chk_this_refd_value(Value *value, Common::Assignment *lhs, expected_v default: if (info.is_subtype_error()) { value->error("%s", info.get_subtype_error().c_str()); - } else if (!info.is_erroneous()) { + } else { CompField* def_alt_ref = governor->get_default_alternative(); Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(ref); if (def_alt_ref != NULL && ttcn_ref != NULL) { @@ -4376,15 +4376,17 @@ bool Type::chk_this_refd_value(Value *value, Common::Assignment *lhs, expected_v value->use_default_alternative(this); return self_ref; } - value->error("Type mismatch: a %s of type `%s' was expected " + if (!info.is_erroneous()) { + value->error("Type mismatch: a %s of type `%s' was expected " "instead of `%s'", expected_value == EXPECTED_TEMPLATE ? "value or template" : "value", get_typename().c_str(), governor->get_typename().c_str()); - } else { - // The semantic error was found by the new code. It was better to - // do the assembly inside TypeCompatInfo. - value->error("%s", info.get_error_str_str().c_str()); + } else { + // The semantic error was found by the new code. It was better to + // do the assembly inside TypeCompatInfo. + value->error("%s", info.get_error_str_str().c_str()); + } } break; } diff --git a/compiler2/Value.cc b/compiler2/Value.cc index 6dd9179434028ce9bf6ffa13a48c21a2dc1e50d1..2302b68d4ed023a74ff80c80067f27ac0868c9db 100644 --- a/compiler2/Value.cc +++ b/compiler2/Value.cc @@ -4946,29 +4946,29 @@ namespace Common { bool compat_t1 = t1->is_compatible(t2, &info1, this, &l_chain1, &r_chain1); bool compat_t2 = t2->is_compatible(t1, &info2, NULL, &l_chain2, &r_chain2); if (!compat_t1 && !compat_t2) { + if (v1->is_ref()) { + CompField* def_alt = t1->get_default_alternative(); + Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(v1->get_reference()); + if (def_alt != NULL && ttcn_ref != NULL) { + Error_Context cntxt(v1, "Using default alternative `%s' in value of union type `%s'", + def_alt->get_name().get_dispname().c_str(), t1->get_typename().c_str()); + ttcn_ref->use_default_alternative(def_alt->get_name()); + return chk_expr_operandtypes_compat(exp_val, v1, v2, opnum1, opnum2); + } + } + if (v2->is_ref()) { + CompField* def_alt = t2->get_default_alternative(); + Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(v2->get_reference()); + if (def_alt != NULL && ttcn_ref != NULL) { + Error_Context cntxt(v2, "Using default alternative `%s' in value of union type `%s'", + def_alt->get_name().get_dispname().c_str(), t2->get_typename().c_str()); + ttcn_ref->use_default_alternative(def_alt->get_name()); + return chk_expr_operandtypes_compat(exp_val, v1, v2, opnum1, opnum2); + } + } if (!info1.is_erroneous() && !info2.is_erroneous()) { // the subtypes don't need to be compatible here if (!info1.is_subtype_error() && !info2.is_subtype_error()) { - if (v1->is_ref()) { - CompField* def_alt = t1->get_default_alternative(); - Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(v1->get_reference()); - if (def_alt != NULL && ttcn_ref != NULL) { - Error_Context cntxt(v1, "Using default alternative `%s' in value of union type `%s'", - def_alt->get_name().get_dispname().c_str(), t1->get_typename().c_str()); - ttcn_ref->use_default_alternative(def_alt->get_name()); - return chk_expr_operandtypes_compat(exp_val, v1, v2, opnum1, opnum2); - } - } - if (v2->is_ref()) { - CompField* def_alt = t2->get_default_alternative(); - Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(v2->get_reference()); - if (def_alt != NULL && ttcn_ref != NULL) { - Error_Context cntxt(v2, "Using default alternative `%s' in value of union type `%s'", - def_alt->get_name().get_dispname().c_str(), t2->get_typename().c_str()); - ttcn_ref->use_default_alternative(def_alt->get_name()); - return chk_expr_operandtypes_compat(exp_val, v1, v2, opnum1, opnum2); - } - } error("The operands of operation `%s' should be of compatible " "types", get_opname()); set_valuetype(V_ERROR);