Skip to content

Commit

Permalink
Explain how to generate good error messages for structural variabilit…
Browse files Browse the repository at this point in the history
…y violation
  • Loading branch information
henrikt-ma committed Dec 9, 2020
1 parent fb341d9 commit 7b3343e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chapters/classes.tex
Expand Up @@ -340,6 +340,21 @@ \subsection{Component Variability Prefixes discrete, parameter, constant}\label{
not differentiable.
\end{itemize}

\begin{nonnormative}
With every normal parameter, there is at least one reason why it isn't a structural parameter.
This information is useful to maintain in tools, as it allows generation of informative error messages when a violation of structural expression variability is detected.
For example:
\begin{lstlisting}[language=modelica]
parameter Integer n =
if b then 1 else 2; /* Normal parameter due to cycle with 'b'. */
parameter Boolean b = n > 3; /* Normal parameter due to cycle with 'n'. */
Real[n] x; /* Variability error: 'n' must be structural. */
\end{lstlisting}
Here, a good error message for the variability error can include the information that the reason for \lstinline!n! being a normal parameter is that it is in a cycle with \lstinline!b!.

(Would structural and normal parameters have had different variability prefixes in their component declarations, it would have been possible to detect and report errors directly at the structural component declarations instead.)
\end{nonnormative}

\begin{nonnormative}
For a parameter in a valid model, presence of \lstinline!Evaluate! (\cref{modelica:Evaluate}) makes it possible to tell immediately whether it is a structural or normal parameter, since \lstinline!Evaluate = false! makes it a normal parameter by definition, and \lstinline!Evaluate = true! is only allowed if the parameter is structural.
\end{nonnormative}
Expand Down

0 comments on commit 7b3343e

Please sign in to comment.