Skip to content

Commit

Permalink
Add test for #3420 return in try-block
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Aug 26, 2015
1 parent 6091fb2 commit 1665199
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions metamodelica/meta/Makefile
Expand Up @@ -96,6 +96,7 @@ Polymorphic.mos \
Polymorphic2.mos \
PolymorphicReduction.mos \
Recursive.mos \
ReturnInTryBlock.mos \
Shadowing1.mos \
Shadowing2.mos \
Simplify1.mos \
Expand Down
53 changes: 53 additions & 0 deletions metamodelica/meta/ReturnInTryBlock.mos
@@ -0,0 +1,53 @@
// status: correct

setCommandLineOptions("-g=MetaModelica -d=noevalfunc");
loadString("
package TestFind

function find<TI, TO>
input list<TI> inList;
input FindFunc inFindFunc;
output TO outElement;

partial function FindFunc
input TI inElement;
output TO outElement;
end FindFunc;
algorithm
for e in inList loop
try
outElement := inFindFunc(e);
return; // This return is dangerous if it does not restore the longjmp pointer after the call finishes
else
end try;
end for;
fail();
end find;

function findTestF
input Integer inI;
output Integer outI;
algorithm
outI := match inI
case 3
then 9;
end match;
end findTestF;

function test
algorithm
find({1,2,3,4}, findTestF);
fail();
end test;

end TestFind;
");

TestFind.test();getErrorString();

// Result:
// true
// true
// fail()
// ""
// endResult

0 comments on commit 1665199

Please sign in to comment.