diff --git a/Compiler/FrontEnd/Algorithm.mo b/Compiler/FrontEnd/Algorithm.mo index ab65cfcdd8c..8bf200b00a0 100644 --- a/Compiler/FrontEnd/Algorithm.mo +++ b/Compiler/FrontEnd/Algorithm.mo @@ -367,6 +367,51 @@ algorithm end match; end makeAssignmentsList; +public function checkLHSWritable +"@author: adrpo + check if the parameters on rhs have fixed = false + and fail otherwise" + input list lhs; + input list props; + input DAE.Exp rhs; + input DAE.ElementSource source; +protected + DAE.Type ty; + Integer i = 1; + String c, l, r; +algorithm + for p in props loop + _ := matchcontinue p + // variables is fine + case DAE.PROP(constFlag = DAE.C_VAR()) then (); + // constant + case DAE.PROP(ty, DAE.C_CONST()) + equation + l = stringAppendList({"(", stringDelimitList(List.map(lhs, ExpressionDump.printExpStr), ", "), ")"}); + r = ExpressionDump.printExpStr(rhs); + Error.addSourceMessage(Error.ASSIGN_CONSTANT_ERROR, {l, r}, ElementSource.getElementSourceFileInfo(source)); + fail(); + then + (); + // parameters + case DAE.PROP(ty, DAE.C_PARAM()) + equation + if Types.getFixedVarAttributeParameterOrConstant(ty) then + l = stringAppendList({"(", stringDelimitList(List.map(lhs, ExpressionDump.printExpStr), ", "), ")"}); + r = ExpressionDump.printExpStr(rhs); + c = ExpressionDump.printExpStr(listGet(lhs, i)); + Error.addSourceMessage(Error.ASSIGN_PARAM_FIXED_ERROR, {c, l, r}, ElementSource.getElementSourceFileInfo(source)); + fail(); + end if; + then + (); + // tuples? TODO! FIXME! can we get tuple here? maybe only for MetaModelica + case DAE.PROP_TUPLE(ty, _) then (); + end matchcontinue; + i := i + 1; + end for; +end checkLHSWritable; + public function makeTupleAssignment "This function creates an `DAE.STMT_TUPLE_ASSIGN\' construct, and checks that the assignment is semantically valid, which means that the component being assigned is not constant, and that the types match." @@ -390,6 +435,7 @@ algorithm list lhrtypes, tpl; list clist; DAE.Type ty; + DAE.Const const; case (lhs, lprop, rhs, _, _, _) equation @@ -416,8 +462,7 @@ algorithm // a normal prop in rhs that contains a T_TUPLE! case (expl, lhprops, rhs, DAE.PROP(type_ = ty as DAE.T_TUPLE(types = tpl)), _, _) equation - bvals = List.map(lhprops, Types.propAnyConst); - DAE.C_VAR() = List.reduce(bvals, Types.constOr); + checkLHSWritable(expl, lhprops, rhs, source); lhrtypes = List.map(lhprops, Types.getPropType); Types.matchTypeTupleCall(rhs, tpl, lhrtypes); /* Don\'t use new rhs\', since type conversions of @@ -426,8 +471,7 @@ algorithm // a tuple in rhs case (expl, lhprops, rhs, DAE.PROP_TUPLE(type_ = ty as DAE.T_TUPLE(types = tpl), tupleConst = DAE.TUPLE_CONST()), _, _) equation - bvals = List.map(lhprops, Types.propAnyConst); - DAE.C_VAR() = List.reduce(bvals, Types.constOr); + checkLHSWritable(expl, lhprops, rhs, source); lhrtypes = List.map(lhprops, Types.getPropType); Types.matchTypeTupleCall(rhs, tpl, lhrtypes); /* Don\'t use new rhs\', since type conversions of several output args are not clearly defined. */ diff --git a/Compiler/Util/Error.mo b/Compiler/Util/Error.mo index 1b9641c8a81..0048c55e4ef 100644 --- a/Compiler/Util/Error.mo +++ b/Compiler/Util/Error.mo @@ -866,6 +866,8 @@ public constant Message USER_TEARING_VARS = MESSAGE(578, SYMBOLIC(), NOTIFICATIO Util.gettext("Following iteration variables are selected by the user for strong component %s (DAE kind: %s):\n%s")); public constant Message CLASS_EXTENDS_TARGET_NOT_FOUND = MESSAGE(579, TRANSLATION(), ERROR(), Util.gettext("Base class targeted by class extends %s not found in the inherited classes.")); +public constant Message ASSIGN_PARAM_FIXED_ERROR = MESSAGE(580, TRANSLATION(), ERROR(), + Util.gettext("Trying to assign to parameter component %s(fixed=true) in %s := %s")); public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(), Util.gettext("Local variable '%s' shadows another variable."));