Skip to content

Commit 20c41e1

Browse files
committed
Fix scope for outer components in getModelInstance
- Use the inner component for lookup when dumping outer components with getModelInstance. Fixes OpenModelica#14795
1 parent d69d5f7 commit 20c41e1

File tree

3 files changed

+254
-1
lines changed

3 files changed

+254
-1
lines changed

OMCompiler/Compiler/Script/NFApi.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ algorithm
13831383
try
13841384
ty_node := Lookup.lookupName(path, scope, InstContext.set(NFInstContext.RELAXED, NFInstContext.FAST_LOOKUP),
13851385
checkAccessViolations = false);
1386-
json := JSON.addPair("type", dumpJSONSCodeClass(InstNode.definition(ty_node), ty_node, scope, isRedeclare = false), json);
1386+
json := JSON.addPair("type", dumpJSONSCodeClass(InstNode.definition(ty_node), ty_node, InstNode.resolveInner(component), isRedeclare = false), json);
13871387
else
13881388
json := JSON.addPair("type", dumpJSONPath(path), json);
13891389
end try;
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
// name: GetModelInstanceInnerOuter6
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
//
7+
8+
loadString("
9+
model A
10+
parameter String s = \"str\";
11+
annotation(Icon(graphics = {Text(textString = s)}));
12+
end A;
13+
14+
model B
15+
outer A a;
16+
end B;
17+
18+
model M
19+
B b;
20+
inner A a;
21+
end M;
22+
");
23+
24+
getModelInstance(M, prettyPrint = true);
25+
26+
// Result:
27+
// true
28+
// "{
29+
// \"name\": \"M\",
30+
// \"restriction\": \"model\",
31+
// \"elements\": [
32+
// {
33+
// \"$kind\": \"component\",
34+
// \"name\": \"b\",
35+
// \"type\": {
36+
// \"name\": \"B\",
37+
// \"restriction\": \"model\",
38+
// \"elements\": [
39+
// {
40+
// \"$kind\": \"component\",
41+
// \"name\": \"a\",
42+
// \"type\": {
43+
// \"$kind\": \"class\",
44+
// \"name\": \"A\",
45+
// \"restriction\": \"model\",
46+
// \"annotation\": {
47+
// \"Icon\": {
48+
// \"graphics\": [
49+
// {
50+
// \"$kind\": \"record\",
51+
// \"name\": \"Text\",
52+
// \"elements\": [
53+
// true,
54+
// [
55+
// 0,
56+
// 0
57+
// ],
58+
// 0,
59+
// [
60+
// 0,
61+
// 0,
62+
// 0
63+
// ],
64+
// [
65+
// 0,
66+
// 0,
67+
// 0
68+
// ],
69+
// {
70+
// \"$kind\": \"enum\",
71+
// \"name\": \"LinePattern.Solid\",
72+
// \"index\": 2
73+
// },
74+
// {
75+
// \"$kind\": \"enum\",
76+
// \"name\": \"FillPattern.None\",
77+
// \"index\": 1
78+
// },
79+
// 0.25,
80+
// [
81+
// [
82+
// -10,
83+
// -10
84+
// ],
85+
// [
86+
// 10,
87+
// 10
88+
// ]
89+
// ],
90+
// {
91+
// \"$kind\": \"cref\",
92+
// \"parts\": [
93+
// {
94+
// \"name\": \"a\"
95+
// },
96+
// {
97+
// \"name\": \"s\"
98+
// }
99+
// ]
100+
// },
101+
// 0,
102+
// [
103+
// -1,
104+
// -1,
105+
// -1
106+
// ],
107+
// \"\",
108+
// [
109+
//
110+
// ],
111+
// {
112+
// \"$kind\": \"enum\",
113+
// \"name\": \"TextAlignment.Center\",
114+
// \"index\": 2
115+
// }
116+
// ]
117+
// }
118+
// ]
119+
// }
120+
// }
121+
// },
122+
// \"prefixes\": {
123+
// \"outer\": true
124+
// }
125+
// }
126+
// ],
127+
// \"source\": {
128+
// \"filename\": \"<interactive>\",
129+
// \"lineStart\": 7,
130+
// \"columnStart\": 3,
131+
// \"lineEnd\": 9,
132+
// \"columnEnd\": 8
133+
// }
134+
// }
135+
// },
136+
// {
137+
// \"$kind\": \"component\",
138+
// \"name\": \"a\",
139+
// \"type\": {
140+
// \"name\": \"A\",
141+
// \"restriction\": \"model\",
142+
// \"annotation\": {
143+
// \"Icon\": {
144+
// \"graphics\": [
145+
// {
146+
// \"$kind\": \"record\",
147+
// \"name\": \"Text\",
148+
// \"elements\": [
149+
// true,
150+
// [
151+
// 0,
152+
// 0
153+
// ],
154+
// 0,
155+
// [
156+
// 0,
157+
// 0,
158+
// 0
159+
// ],
160+
// [
161+
// 0,
162+
// 0,
163+
// 0
164+
// ],
165+
// {
166+
// \"$kind\": \"enum\",
167+
// \"name\": \"LinePattern.Solid\",
168+
// \"index\": 2
169+
// },
170+
// {
171+
// \"$kind\": \"enum\",
172+
// \"name\": \"FillPattern.None\",
173+
// \"index\": 1
174+
// },
175+
// 0.25,
176+
// [
177+
// [
178+
// -10,
179+
// -10
180+
// ],
181+
// [
182+
// 10,
183+
// 10
184+
// ]
185+
// ],
186+
// {
187+
// \"$kind\": \"cref\",
188+
// \"parts\": [
189+
// {
190+
// \"name\": \"a\"
191+
// },
192+
// {
193+
// \"name\": \"s\"
194+
// }
195+
// ]
196+
// },
197+
// 0,
198+
// [
199+
// -1,
200+
// -1,
201+
// -1
202+
// ],
203+
// \"\",
204+
// [
205+
//
206+
// ],
207+
// {
208+
// \"$kind\": \"enum\",
209+
// \"name\": \"TextAlignment.Center\",
210+
// \"index\": 2
211+
// }
212+
// ]
213+
// }
214+
// ]
215+
// }
216+
// },
217+
// \"elements\": [
218+
// {
219+
// \"$kind\": \"component\",
220+
// \"name\": \"s\",
221+
// \"type\": \"String\",
222+
// \"modifiers\": \"\\\"str\\\"\",
223+
// \"value\": {
224+
// \"binding\": \"str\"
225+
// },
226+
// \"prefixes\": {
227+
// \"variability\": \"parameter\"
228+
// }
229+
// }
230+
// ],
231+
// \"source\": {
232+
// \"filename\": \"<interactive>\",
233+
// \"lineStart\": 2,
234+
// \"columnStart\": 3,
235+
// \"lineEnd\": 5,
236+
// \"columnEnd\": 8
237+
// }
238+
// },
239+
// \"prefixes\": {
240+
// \"inner\": true
241+
// }
242+
// }
243+
// ],
244+
// \"source\": {
245+
// \"filename\": \"<interactive>\",
246+
// \"lineStart\": 11,
247+
// \"columnStart\": 3,
248+
// \"lineEnd\": 14,
249+
// \"columnEnd\": 8
250+
// }
251+
// }"
252+
// endResult

testsuite/openmodelica/instance-API/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ GetModelInstanceInnerOuter3.mos \
7272
GetModelInstanceInnerOuter4.mos \
7373
GetModelInstanceInnerOuter5.mos \
7474
GetModelInstanceInnerOuter6.mos \
75+
GetModelInstanceInnerOuter7.mos \
7576
GetModelInstanceMissingClass1.mos \
7677
GetModelInstanceMissingClass2.mos \
7778
GetModelInstanceMissingClass3.mos \

0 commit comments

Comments
 (0)