Skip to content

Commit

Permalink
Instantiate record constructors as functions (#12362)
Browse files Browse the repository at this point in the history
- Instantiate record constructors as functions, to avoid creating
  binding equations from start values for parameters without bindings.
  • Loading branch information
perost committed May 2, 2024
1 parent 337cd07 commit 7b27e79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFRecord.mo
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ algorithm
end try;

next_context := InstContext.set(context, NFInstContext.RELAXED);
next_context := InstContext.set(next_context, NFInstContext.FUNCTION);
recordNode := InstNode.setNodeType(NFInstNode.InstNodeType.ROOT_CLASS(InstNode.parent(node)), recordNode);
recordNode := Inst.instantiate(recordNode, context = next_context);
Inst.instExpressions(recordNode, context = next_context);
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 @@ -994,6 +994,7 @@ RecordBinding13.mo \
RecordConstructor1.mo \
RecordConstructor2.mo \
RecordConstructor3.mo \
RecordConstructor4.mo \
RecordExtends1.mo \
RecordExtends2.mo \
RecordUnknownDim1.mo \
Expand Down
31 changes: 31 additions & 0 deletions testsuite/flattening/modelica/scodeinst/RecordConstructor4.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// name: RecordConstructor4
// keywords:
// status: correct
// cflags: -d=newInst
//
//

record R
parameter Real x(start = 1.0);
end R;

model RecordConstructor4
R r;
equation
r = R(time);
end RecordConstructor4;

// Result:
// function R "Automatically generated record constructor for R"
// input Real x;
// output R res;
// end R;
//
// class RecordConstructor4
// parameter Real r.x(start = 1.0);
// equation
// r = R(time);
// end RecordConstructor4;
// [flattening/modelica/scodeinst/RecordConstructor4.mo:9:3-9:32:writable] Warning: Parameter r.x has no value, and is fixed during initialization (fixed=true), using available start value (start=1.0) as default value.
//
// endResult

0 comments on commit 7b27e79

Please sign in to comment.