Skip to content

Commit

Permalink
Add a generic error message for function instantiation (#7177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Feb 17, 2021
1 parent ea1a004 commit c07c4ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -477,8 +477,18 @@ uniontype Function
input output InstNode fnNode;
input InstContext.Type context;
input SourceInfo info;
protected
SCode.Element def;
Integer numError = Error.getNumErrorMessages();
algorithm
fnNode := Inst.instantiate(fnNode, context = context, instPartial = true);
try
fnNode := Inst.instantiate(fnNode, context = context, instPartial = true);
else
true := Error.getNumErrorMessages() == numError;
def := InstNode.definition(fnNode);
Error.addSourceMessage(Error.UNKNOWN_ERROR_INST_FUNCTION, {SCodeDump.unparseElementStr(def)}, SCodeUtil.elementInfo(def));
fail();
end try;

// Set up an empty function cache to signal that this function is
// currently being instantiated, so recursive functions can be handled.
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/Util/Error.mo
Expand Up @@ -1060,6 +1060,8 @@ public constant ErrorTypes.Message NOTIFY_PKG_NO_INSTALL = ErrorTypes.MESSAGE(61
Gettext.gettext("%s %s will not be installed since version %s is installed."));
public constant ErrorTypes.Message DEPRECATED_FLAG = ErrorTypes.MESSAGE(614, ErrorTypes.SCRIPTING(), ErrorTypes.WARNING(),
Gettext.gettext("The flag '%s' is deprecated. Please use '%s' instead."));
public constant ErrorTypes.Message UNKNOWN_ERROR_INST_FUNCTION = ErrorTypes.MESSAGE(615, ErrorTypes.TRANSLATION(), ErrorTypes.INTERNAL(),
Gettext.gettext("Unknown error trying to instantiate function: %s."));

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

0 comments on commit c07c4ac

Please sign in to comment.