From debacc085b262705bfe92bf7fac4131a7ee66f11 Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Thu, 3 Mar 2022 18:52:09 +0100
Subject: [PATCH] XER: fixed untagged optional union decoding error (issue
 #585)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
---
 compiler2/union.c            | 2 +-
 regression_test/XML/Makefile | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler2/union.c b/compiler2/union.c
index a397195da..8ee0cbf2b 100644
--- a/compiler2/union.c
+++ b/compiler2/union.c
@@ -2012,7 +2012,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       }
       if (!sdef->isOptional) {
         src = mputstr(src,
-          "    else {\n"
+          "    else if (!(p_flavor & XER_OPTIONAL)) {\n"
           "      ec_1.set_msg(\" \");\n"
           "      TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG, "
           "\"'%s' does not match any alternative\", elem_name);\n"
diff --git a/regression_test/XML/Makefile b/regression_test/XML/Makefile
index 43c226eaf..10dbffeee 100644
--- a/regression_test/XML/Makefile
+++ b/regression_test/XML/Makefile
@@ -30,7 +30,8 @@ endif
 XDIRS := $(wildcard $(SHADOWED)) xsdConverter \
 HM60295 HN15589 HQ30408 HR49727 HU13380 $(RT2_ONLY) \
 XmlWorkflow tpdValidTest AbstractBlock UseNilLong AttributeFormDefault \
-RecordOmit XSDBaseType LegacyUntaggedUnion Printing Bug570707
+RecordOmit XSDBaseType LegacyUntaggedUnion Printing Bug570707 \
+Issue545 Issue585
 
 # List of fake targets:
 .PHONY: all dep clean run $(XDIRS) $(addsuffix /, $(XDIRS)) profile
-- 
GitLab