Skip to content

Commit b8f9594

Browse files
authored
Check that complex types have the same named elements (#10804)
1 parent 70ccdde commit b8f9594

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

OMCompiler/Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,11 @@ algorithm
18161816
matchKind := MatchKind.NOT_COMPATIBLE;
18171817
else
18181818
for i in 1:arrayLength(comps1) loop
1819+
if InstNode.name(comps1[i]) <> InstNode.name(comps2[i]) then
1820+
matchKind := MatchKind.NOT_COMPATIBLE;
1821+
break;
1822+
end if;
1823+
18191824
comp2 := InstNode.component(comps2[i]);
18201825

18211826
if Component.isTyped(comp2) then
@@ -1871,6 +1876,11 @@ algorithm
18711876
matchKind := MatchKind.NOT_COMPATIBLE;
18721877
else
18731878
for i in 1:arrayLength(comps1) loop
1879+
if InstNode.name(comps1[i]) <> InstNode.name(comps2[i]) then
1880+
matchKind := MatchKind.NOT_COMPATIBLE;
1881+
break;
1882+
end if;
1883+
18741884
comp2 := InstNode.component(comps2[i]);
18751885

18761886
if Component.isTyped(comp2) then
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// name: FuncWrongType2
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that type checking works for functions.
7+
//
8+
9+
record A
10+
Real a1;
11+
end A;
12+
13+
record B
14+
Real b1;
15+
end B;
16+
17+
function F
18+
input A in_a;
19+
end F;
20+
21+
model FuncWrongType2
22+
B b(b1 = time);
23+
algorithm
24+
F(b);
25+
end FuncWrongType2;
26+
27+
// Result:
28+
// Error processing file: FuncWrongType2.mo
29+
// [flattening/modelica/scodeinst/FuncWrongType2.mo:24:3-24:7:writable] Error: Type mismatch for positional argument 1 in F(in_a=b). The argument has type:
30+
// B
31+
// expected type:
32+
// A
33+
//
34+
// # Error encountered! Exiting...
35+
// # Please check the error message and the flags.
36+
//
37+
// Execution failed!
38+
// endResult

testsuite/flattening/modelica/scodeinst/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ FuncVectorizationCastConflict1.mo \
639639
FuncVectorizationMap1.mo \
640640
FuncWildcard.mo \
641641
FuncWrongType.mo \
642+
FuncWrongType2.mo \
642643
FunctionalArg1.mo \
643644
FunctionalArg2.mo \
644645
FunctionalArg3.mo \

0 commit comments

Comments
 (0)