Skip to content

Commit 1665199

Browse files
committed
Add test for #3420 return in try-block
1 parent 6091fb2 commit 1665199

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

metamodelica/meta/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Polymorphic.mos \
9696
Polymorphic2.mos \
9797
PolymorphicReduction.mos \
9898
Recursive.mos \
99+
ReturnInTryBlock.mos \
99100
Shadowing1.mos \
100101
Shadowing2.mos \
101102
Simplify1.mos \
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// status: correct
2+
3+
setCommandLineOptions("-g=MetaModelica -d=noevalfunc");
4+
loadString("
5+
package TestFind
6+
7+
function find<TI, TO>
8+
input list<TI> inList;
9+
input FindFunc inFindFunc;
10+
output TO outElement;
11+
12+
partial function FindFunc
13+
input TI inElement;
14+
output TO outElement;
15+
end FindFunc;
16+
algorithm
17+
for e in inList loop
18+
try
19+
outElement := inFindFunc(e);
20+
return; // This return is dangerous if it does not restore the longjmp pointer after the call finishes
21+
else
22+
end try;
23+
end for;
24+
fail();
25+
end find;
26+
27+
function findTestF
28+
input Integer inI;
29+
output Integer outI;
30+
algorithm
31+
outI := match inI
32+
case 3
33+
then 9;
34+
end match;
35+
end findTestF;
36+
37+
function test
38+
algorithm
39+
find({1,2,3,4}, findTestF);
40+
fail();
41+
end test;
42+
43+
end TestFind;
44+
");
45+
46+
TestFind.test();getErrorString();
47+
48+
// Result:
49+
// true
50+
// true
51+
// fail()
52+
// ""
53+
// endResult

0 commit comments

Comments
 (0)