Skip to content

Commit

Permalink
Fix evaluation of call type dimensions (OpenModelica#12618)
Browse files Browse the repository at this point in the history
- Mark dimension expressions as structural when evaluating the type
  of a function call, to avoid having them be marked as non-structural
  when they depend on external functions.

Fixes OpenModelica#12605
  • Loading branch information
perost committed Jun 19, 2024
1 parent c399c46 commit 53a0a89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Prefixes = NFPrefixes;
import Restriction = NFRestriction;
import SCodeUtil;
import SimplifyExp = NFSimplifyExp;
import Structural = NFStructural;
import Subscript = NFSubscript;
import TypeCheck = NFTypeCheck;
import Typing = NFTyping;
Expand Down Expand Up @@ -2842,6 +2843,7 @@ protected

ErrorExt.setCheckpoint(getInstanceName());
try
Structural.markExp(exp);
exp := Ceval.evalExp(exp);
else
end try;
Expand Down
41 changes: 41 additions & 0 deletions testsuite/flattening/modelica/scodeinst/DimUnknown16.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// name: DimUnknown16
// keywords:
// status: correct
// cflags: -d=newInst
//
//

function f
input Integer nrow;
input Integer ncol;
output Real[nrow, ncol] matrix;
external "C" f(nrow, ncol, matrix);
end f;

impure function f2
input Integer dummy;
output Integer dim;
external "C" dim = strlen("aa");
end f2;

model DimUnknown16
parameter Integer dummy = 0;
parameter Integer dim = f2(dummy);
parameter Real A[:, :] = f(dim, dim);
end DimUnknown16;

// Result:
// impure function f
// input Integer nrow;
// input Integer ncol;
// output Real[nrow, ncol] matrix;
//
// external "C" f(nrow, ncol, matrix);
// end f;
//
// class DimUnknown16
// final parameter Integer dummy = 0;
// final parameter Integer dim = 2;
// parameter Real[2, 2] A = f(2, 2);
// end DimUnknown16;
// endResult
4 changes: 2 additions & 2 deletions testsuite/flattening/modelica/scodeinst/FuncUnknownDim3.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function f
input Real[n] v;
output Real[n] result = fill(1.0, n);
protected
parameter Integer n = size(v, 1);
Integer n = size(v, 1);
end f;

model FuncUnknownDim3
Expand All @@ -19,7 +19,7 @@ end FuncUnknownDim3;
// function f
// input Real[n] v;
// output Real[n] result = fill(1.0, n);
// protected parameter Integer n = size(v, 1);
// protected Integer n = size(v, 1);
// end f;
//
// class FuncUnknownDim3
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ DimUnknown12.mo \
DimUnknown13.mo \
DimUnknown14.mo \
DimUnknown15.mo \
DimUnknown16.mo \
dim1.mo \
dim13.mo \
dim16.mo \
Expand Down

0 comments on commit 53a0a89

Please sign in to comment.