Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 25da467

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
[NF] Relax variability error in functions
The binding expression of a parameter in a function is now allowed to be a discrete expression (since we do not distinguish between inputs and other bindings). This now gives a warning instead of an error (because the Modelica specification does not seem to allow this, but other tools and libraries use this pattern for no obvious reason). Belonging to [master]: - #2321
1 parent 3a6cb88 commit 25da467

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,16 @@ algorithm
621621
comp_var := Component.variability(c);
622622

623623
if Binding.variability(binding) > comp_var then
624-
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING,
625-
{name, Prefixes.variabilityString(Component.variability(c)),
626-
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))},
627-
Binding.getInfo(binding));
628-
fail();
624+
if comp_var == Variability.PARAMETER and intBitAnd(origin, ExpOrigin.FUNCTION) > 0 then
625+
Error.addSourceMessage(Error.FUNCTION_HIGHER_VARIABILITY_BINDING, {name, Prefixes.variabilityString(Component.variability(c)),
626+
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))}, Binding.getInfo(binding));
627+
else
628+
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING,
629+
{name, Prefixes.variabilityString(Component.variability(c)),
630+
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))},
631+
Binding.getInfo(binding));
632+
fail();
633+
end if;
629634
end if;
630635

631636
// Evaluate the binding if the component is a constant.

Compiler/Util/Error.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ public constant Message NON_STATE_STATESELECT_ALWAYS = MESSAGE(591, SYMBOLIC(),
963963
Util.gettext("Variable %s has attribute stateSelect=StateSelect.always, but was selected as a continuous variable."));
964964
public constant Message STATE_STATESELECT_NEVER = MESSAGE(592, SYMBOLIC(), WARNING(),
965965
Util.gettext("Variable %s has attribute stateSelect=StateSelect.never, but was selected as a state"));
966+
public constant Message FUNCTION_HIGHER_VARIABILITY_BINDING = MESSAGE(593, TRANSLATION(), WARNING(),
967+
Util.gettext("Component ‘%s’ of variability %s has binding %s of higher variability %s."));
966968

967969
public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(),
968970
Util.gettext("Local variable '%s' shadows another variable."));

0 commit comments

Comments
 (0)