diff --git a/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo b/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo index 58a1050d782..4de9e583e9b 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo @@ -3091,6 +3091,12 @@ algorithm (cond, ty, var) := typeCondition(cond, context, source, Error.WHEN_CONDITION_TYPE_ERROR, allowVector = true, allowClock = true); + if var > Variability.IMPLICITLY_DISCRETE and not Type.isClock(ty) then + Error.addSourceMessage(Error.NON_DISCRETE_WHEN_CONDITION, + {Expression.toString(cond)}, ElementSource.getInfo(source)); + fail(); + end if; + if not checkWhenInitial(cond) then Error.addSourceMessage(Error.INITIAL_CALL_WARNING, {Expression.toString(cond)}, ElementSource.getInfo(source)); diff --git a/OMCompiler/Compiler/Util/Error.mo b/OMCompiler/Compiler/Util/Error.mo index b1b7e736855..f6d449c4e25 100644 --- a/OMCompiler/Compiler/Util/Error.mo +++ b/OMCompiler/Compiler/Util/Error.mo @@ -834,6 +834,8 @@ public constant ErrorTypes.Message MISSING_INNER_NAME_CONFLICT = ErrorTypes.MESS Gettext.gettext("An inner declaration for outer component ‘%s‘ could not be found, and could not be automatically generated due to a existing declaration of that name.")); public constant ErrorTypes.Message TOP_LEVEL_INPUT_WITH_BINDING = ErrorTypes.MESSAGE(381, ErrorTypes.TRANSLATION(), ErrorTypes.NOTIFICATION(), Gettext.gettext("Top-level input ‘%s‘ has a binding equation and will not be accessible as an input of the model.")); +public constant ErrorTypes.Message NON_DISCRETE_WHEN_CONDITION = ErrorTypes.MESSAGE(382, ErrorTypes.TRANSLATION(), ErrorTypes.ERROR(), + Gettext.gettext("When-condition ‘%s‘ is not a discrete-time expression.")); public constant ErrorTypes.Message INITIALIZATION_NOT_FULLY_SPECIFIED = ErrorTypes.MESSAGE(496, ErrorTypes.TRANSLATION(), ErrorTypes.WARNING(), Gettext.gettext("The initial conditions are not fully specified. %s.")); diff --git a/testsuite/flattening/modelica/scodeinst/Makefile b/testsuite/flattening/modelica/scodeinst/Makefile index 2b516d60c87..fd03dea1e6b 100644 --- a/testsuite/flattening/modelica/scodeinst/Makefile +++ b/testsuite/flattening/modelica/scodeinst/Makefile @@ -913,6 +913,10 @@ WhenClockedElse1.mo \ WhenClockedElse2.mo \ WhenClockedStatement1.mo \ WhenClockedTupleCall1.mo \ +WhenCondition1.mo \ +WhenCondition2.mo \ +WhenCondition3.mo \ +WhenCondition4.mo \ WhenIllegalContext1.mo \ WhenIllegalContext2.mo \ WhenIllegalContext3.mo \ diff --git a/testsuite/flattening/modelica/scodeinst/WhenCondition1.mo b/testsuite/flattening/modelica/scodeinst/WhenCondition1.mo new file mode 100644 index 00000000000..fe9ee92c806 --- /dev/null +++ b/testsuite/flattening/modelica/scodeinst/WhenCondition1.mo @@ -0,0 +1,26 @@ +// name: WhenCondition1 +// keywords: +// status: correct +// cflags: -d=newInst +// +// + +model WhenCondition1 + Boolean b; + Real x; +equation + when b then + x = 1.0; + end when; +end WhenCondition1; + +// Result: +// class WhenCondition1 +// Boolean b; +// Real x; +// equation +// when b then +// x = 1.0; +// end when; +// end WhenCondition1; +// endResult diff --git a/testsuite/flattening/modelica/scodeinst/WhenCondition2.mo b/testsuite/flattening/modelica/scodeinst/WhenCondition2.mo new file mode 100644 index 00000000000..d976d49d0c9 --- /dev/null +++ b/testsuite/flattening/modelica/scodeinst/WhenCondition2.mo @@ -0,0 +1,26 @@ +// name: WhenCondition2 +// keywords: +// status: correct +// cflags: -d=newInst +// +// + +model WhenCondition2 + Boolean b; + Real x; +equation + when {b, initial()} then + x = 1.0; + end when; +end WhenCondition2; + +// Result: +// class WhenCondition2 +// Boolean b; +// Real x; +// equation +// when {b, initial()} then +// x = 1.0; +// end when; +// end WhenCondition2; +// endResult diff --git a/testsuite/flattening/modelica/scodeinst/WhenCondition3.mo b/testsuite/flattening/modelica/scodeinst/WhenCondition3.mo new file mode 100644 index 00000000000..30326294a29 --- /dev/null +++ b/testsuite/flattening/modelica/scodeinst/WhenCondition3.mo @@ -0,0 +1,24 @@ +// name: WhenCondition3 +// keywords: +// status: correct +// cflags: -d=newInst +// +// + +model WhenCondition3 + Real x; +equation + when time > 0 then + x = 1.0; + end when; +end WhenCondition3; + +// Result: +// class WhenCondition3 +// Real x; +// equation +// when time > 0.0 then +// x = 1.0; +// end when; +// end WhenCondition3; +// endResult diff --git a/testsuite/flattening/modelica/scodeinst/WhenCondition4.mo b/testsuite/flattening/modelica/scodeinst/WhenCondition4.mo new file mode 100644 index 00000000000..88360788726 --- /dev/null +++ b/testsuite/flattening/modelica/scodeinst/WhenCondition4.mo @@ -0,0 +1,24 @@ +// name: WhenCondition4 +// keywords: +// status: incorrect +// cflags: -d=newInst +// +// + +model WhenCondition4 + Real x; +equation + when noEvent(time > 0) then + x = 1.0; + end when; +end WhenCondition4; + +// Result: +// Error processing file: WhenCondition4.mo +// [flattening/modelica/scodeinst/WhenCondition4.mo:11:3-13:11:writable] Error: When-condition ‘noEvent(time > 0.0)‘ is not a discrete-time expression. +// +// # Error encountered! Exiting... +// # Please check the error message and the flags. +// +// Execution failed! +// endResult