diff --git a/Compiler/FrontEnd/ComponentReference.mo b/Compiler/FrontEnd/ComponentReference.mo index 8da1e9f8fdf..ed377b538d5 100644 --- a/Compiler/FrontEnd/ComponentReference.mo +++ b/Compiler/FrontEnd/ComponentReference.mo @@ -1291,9 +1291,8 @@ algorithm case (cr) equation ((subs as (_ :: _))) = crefLastSubs(cr); - exps = List.map(subs, Expression.subscriptIndexExp); // fails if any mapped functions returns false - then List.mapAllValueBool(exps, Expression.isOne, true); + then List.mapAllValueBool(subs, Expression.subscriptIsFirst, true); else false; end matchcontinue; end crefIsFirstArrayElt; diff --git a/Compiler/FrontEnd/Expression.mo b/Compiler/FrontEnd/Expression.mo index d5e84749fc6..2239fbe9563 100644 --- a/Compiler/FrontEnd/Expression.mo +++ b/Compiler/FrontEnd/Expression.mo @@ -1609,6 +1609,22 @@ algorithm end match; end subscriptNonExpandedExp; +public function subscriptIsFirst + "Returns true if the given subscript is the first index for a dimension, i.e. + 1, false or the first enumeration literal in an enumeration." + input Subscript inSubscript; + output Boolean outIsFirst; +algorithm + outIsFirst := match(inSubscript) + local + + case DAE.INDEX(exp = DAE.ICONST(1)) then true; + case DAE.INDEX(exp = DAE.BCONST(false)) then true; + case DAE.INDEX(exp = DAE.ENUM_LITERAL(index = 1)) then true; + + end match; +end subscriptIsFirst; + public function nthArrayExp "function: nthArrayExp author: PA diff --git a/Compiler/Template/CodegenUtil.tpl b/Compiler/Template/CodegenUtil.tpl index 370762aaeb8..d325a9831ee 100644 --- a/Compiler/Template/CodegenUtil.tpl +++ b/Compiler/Template/CodegenUtil.tpl @@ -72,6 +72,7 @@ template subscriptStr(Subscript subscript) ::= match subscript case INDEX(exp=ICONST(integer=i)) then i + case INDEX(exp=ENUM_LITERAL(name=n)) then dotPath(n) case SLICE(exp=ICONST(integer=i)) then i case WHOLEDIM(__) then "WHOLEDIM" else "UNKNOWN_SUBSCRIPT"