Skip to content

Commit

Permalink
[NF] Relax variability error in functions
Browse files Browse the repository at this point in the history
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]:
  - OpenModelica/OMCompiler#2321
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 27, 2018
1 parent 3a6cb88 commit 25da467
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -621,11 +621,16 @@ algorithm
comp_var := Component.variability(c);

if Binding.variability(binding) > comp_var then
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING,
{name, Prefixes.variabilityString(Component.variability(c)),
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))},
Binding.getInfo(binding));
fail();
if comp_var == Variability.PARAMETER and intBitAnd(origin, ExpOrigin.FUNCTION) > 0 then
Error.addSourceMessage(Error.FUNCTION_HIGHER_VARIABILITY_BINDING, {name, Prefixes.variabilityString(Component.variability(c)),
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))}, Binding.getInfo(binding));
else
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING,
{name, Prefixes.variabilityString(Component.variability(c)),
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(Binding.variability(binding))},
Binding.getInfo(binding));
fail();
end if;
end if;

// Evaluate the binding if the component is a constant.
Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -963,6 +963,8 @@ public constant Message NON_STATE_STATESELECT_ALWAYS = MESSAGE(591, SYMBOLIC(),
Util.gettext("Variable %s has attribute stateSelect=StateSelect.always, but was selected as a continuous variable."));
public constant Message STATE_STATESELECT_NEVER = MESSAGE(592, SYMBOLIC(), WARNING(),
Util.gettext("Variable %s has attribute stateSelect=StateSelect.never, but was selected as a state"));
public constant Message FUNCTION_HIGHER_VARIABILITY_BINDING = MESSAGE(593, TRANSLATION(), WARNING(),
Util.gettext("Component ‘%s’ of variability %s has binding %s of higher variability %s."));

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

0 comments on commit 25da467

Please sign in to comment.