Skip to content

Commit 0e8be87

Browse files
authored
Don't fail on invalid each usage in getModelInstance (#11493)
1 parent fd4e05a commit 0e8be87

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

OMCompiler/Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,10 @@ algorithm
28622862
if not isValidAssignmentMatch(ty_match) then
28632863
binding.bindingExp := Expression.expandSplitIndices(exp);
28642864
printBindingTypeError(name, binding, comp_ty, bind_ty, component, context);
2865-
fail();
2865+
2866+
if not InstContext.inInstanceAPI(context) then
2867+
fail();
2868+
end if;
28662869
elseif isCastMatch(ty_match) then
28672870
binding := Binding.TYPED_BINDING(exp, ty, binding.variability, binding.eachType,
28682871
binding.evalState, binding.isFlattened, binding.source, binding.info);

testsuite/openmodelica/instance-API/GetModelInstanceBinding7.mos

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ getErrorString();
2525
// \"name\": \"x\",
2626
// \"type\": \"Real\",
2727
// \"modifiers\": \"\\\"s\\\"\",
28+
// \"value\": {
29+
// \"binding\": \"s\"
30+
// },
2831
// \"prefixes\": {
2932
// \"variability\": \"parameter\"
3033
// }
@@ -38,5 +41,6 @@ getErrorString();
3841
// \"columnEnd\": 8
3942
// }
4043
// }"
41-
// ""
44+
// "[<interactive>:3:5-3:27:writable] Error: Type mismatch in binding x = \"s\", expected subtype of Real, got type String.
45+
// "
4246
// endResult
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// name: GetModelInstanceBinding8
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
//
7+
8+
loadString("
9+
model A
10+
Real x;
11+
end A;
12+
13+
model M
14+
A a1[3](x = 1.0);
15+
A a2(each x = 1.0);
16+
end M;
17+
");
18+
19+
getModelInstance(M, prettyPrint = true);
20+
getErrorString();
21+
22+
// Result:
23+
// true
24+
// "{
25+
// \"name\": \"M\",
26+
// \"restriction\": \"model\",
27+
// \"elements\": [
28+
// {
29+
// \"$kind\": \"component\",
30+
// \"name\": \"a1\",
31+
// \"type\": {
32+
// \"name\": \"A\",
33+
// \"restriction\": \"model\",
34+
// \"elements\": [
35+
// {
36+
// \"$kind\": \"component\",
37+
// \"name\": \"x\",
38+
// \"type\": \"Real\",
39+
// \"value\": {
40+
// \"binding\": 1
41+
// }
42+
// }
43+
// ],
44+
// \"source\": {
45+
// \"filename\": \"<interactive>\",
46+
// \"lineStart\": 2,
47+
// \"columnStart\": 3,
48+
// \"lineEnd\": 4,
49+
// \"columnEnd\": 8
50+
// }
51+
// },
52+
// \"dims\": {
53+
// \"absyn\": [
54+
// \"3\"
55+
// ],
56+
// \"typed\": [
57+
// \"3\"
58+
// ]
59+
// },
60+
// \"modifiers\": {
61+
// \"x\": \"1.0\"
62+
// }
63+
// },
64+
// {
65+
// \"$kind\": \"component\",
66+
// \"name\": \"a2\",
67+
// \"type\": {
68+
// \"name\": \"A\",
69+
// \"restriction\": \"model\",
70+
// \"elements\": [
71+
// {
72+
// \"$kind\": \"component\",
73+
// \"name\": \"x\",
74+
// \"type\": \"Real\",
75+
// \"value\": {
76+
// \"binding\": 1
77+
// }
78+
// }
79+
// ],
80+
// \"source\": {
81+
// \"filename\": \"<interactive>\",
82+
// \"lineStart\": 2,
83+
// \"columnStart\": 3,
84+
// \"lineEnd\": 4,
85+
// \"columnEnd\": 8
86+
// }
87+
// },
88+
// \"modifiers\": {
89+
// \"x\": {
90+
// \"each\": true,
91+
// \"$value\": \"1.0\"
92+
// }
93+
// }
94+
// }
95+
// ],
96+
// \"source\": {
97+
// \"filename\": \"<interactive>\",
98+
// \"lineStart\": 6,
99+
// \"columnStart\": 3,
100+
// \"lineEnd\": 9,
101+
// \"columnEnd\": 8
102+
// }
103+
// }"
104+
// "[<interactive>:7:13-7:20:writable] Notification: From here:
105+
// [<interactive>:3:5-3:11:writable] Error: Non-array modification '1.0' for array component 'x', possibly due to missing 'each'.
106+
// "
107+
// endResult

testsuite/openmodelica/instance-API/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ GetModelInstanceBinding4.mos \
2020
GetModelInstanceBinding5.mos \
2121
GetModelInstanceBinding6.mos \
2222
GetModelInstanceBinding7.mos \
23+
GetModelInstanceBinding8.mos \
2324
GetModelInstanceBreak1.mos \
2425
GetModelInstanceChoices1.mos \
2526
GetModelInstanceChoices2.mos \

0 commit comments

Comments
 (0)