Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for #3420 return in try-block
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |