Skip to content

Commit

Permalink
Port frontend fixes to 1.23 (#12301)
Browse files Browse the repository at this point in the history
* Handle too many subscripts in Type.subscript (#12299)

- Don't fail in `Type.subscript` if too many subscripts are given and
  `failOnError=false`.

Fixes #12296

* Handle uninstantiated dimension in Dimension.toString (#12300)

- Add case for `Dimension.RAW_DIM` in `Dimension.toString`.

Fixes #12297
  • Loading branch information
perost committed Apr 23, 2024
1 parent b595415 commit eb2a157
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFDimension.mo
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
encapsulated uniontype NFDimension
protected
import Dimension = NFDimension;
import Dump;
import Operator = NFOperator;
import Prefixes = NFPrefixes;
import List;
Expand Down Expand Up @@ -368,6 +369,7 @@ public
local
Type ty;

case RAW_DIM() then Dump.printSubscriptStr(dim.dim);
case INTEGER() then String(dim.size);
case BOOLEAN() then "Boolean";
case ENUM(enumType = ty as Type.ENUMERATION()) then AbsynUtil.pathString(ty.typePath);
Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFType.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ public
end if;

ty := match ty
case ARRAY(dimensions = dims)
guard not failOnError and listLength(subs) > listLength(dims)
then Type.UNKNOWN();

case ARRAY(dimensions = dims)
algorithm
for sub in subs loop
Expand Down
20 changes: 20 additions & 0 deletions testsuite/flattening/modelica/scodeinst/BuiltinAttribute24.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// name: BuiltinAttribute23
// keywords:
// status: incorrect
// cflags: -d=newInst
//

model BuiltinAttribute24
Real x[2,2](start = {3,1});
end BuiltinAttribute24;

// Result:
// Error processing file: BuiltinAttribute24.mo
// [flattening/modelica/scodeinst/BuiltinAttribute24.mo:8:15-8:28:writable] Notification: From here:
// [flattening/modelica/scodeinst/BuiltinAttribute24.mo:8:3-8:29:writable] Error: Type mismatch in binding 'start = {3.0, 1.0}', expected array dimensions [2, 2], got [2].
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
32 changes: 32 additions & 0 deletions testsuite/flattening/modelica/scodeinst/DuplicateElements11.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// name: DuplicateElements11
// keywords:
// status: incorrect
// cflags: -d=newInst
//
//

model A
Real x[3];
end A;

model B
Real x[3];
end B;

model DuplicateElements11
extends A(x = {1, 2, 3});
extends B;
end DuplicateElements11;

// Result:
// Error processing file: DuplicateElements11.mo
// [flattening/modelica/scodeinst/DuplicateElements11.mo:9:3-9:12:writable] Notification: From here:
// [flattening/modelica/scodeinst/DuplicateElements11.mo:13:3-13:12:writable] Error: Duplicate elements (due to inherited elements) not identical:
// first element is: Real[3] x = {1, 2, 3}
// second element is: Real[3] x
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
2 changes: 2 additions & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ BuiltinAttribute20.mo \
BuiltinAttribute21.mo \
BuiltinAttribute22.mo \
BuiltinAttribute23.mo \
BuiltinAttribute24.mo \
BuiltinLookup1.mo \
BuiltinTime.mo \
BuiltinTimeSubscripted.mo \
Expand Down Expand Up @@ -383,6 +384,7 @@ DuplicateElements4.mo \
DuplicateElements5.mo \
DuplicateElements9.mo \
DuplicateElements10.mo \
DuplicateElements11.mo \
DuplicateElementsValid1.mo \
DuplicateElementsValid2.mo \
DuplicateMod1.mo \
Expand Down

0 comments on commit eb2a157

Please sign in to comment.