Skip to content

Commit a22d2f1

Browse files
committed
[cppia] Test for method on exception throwing expr
1 parent 653c22b commit a22d2f1

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

test/cppia/Client.hx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ class Client
189189
default:
190190
}
191191

192+
switch LocalFunctionExceptions.testObjMethodOnReturn() {
193+
case Error(message):
194+
Common.status = 'Failed test for running object method on returned value: ' + message;
195+
return;
196+
default:
197+
}
198+
199+
switch LocalFunctionExceptions.testClassMethodOnReturn() {
200+
case Error(message):
201+
Common.status = 'Failed test for running class method on returned value: ' + message;
202+
return;
203+
default:
204+
}
205+
192206
// regression test for #926
193207
var x:Dynamic = 3;
194208
x *= 5;

test/cppia/LocalFunctionExceptions.hx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ enum Status {
33
Error(message:String);
44
}
55

6+
class DummyClass {
7+
public function run() {}
8+
}
9+
610
class LocalFunctionExceptions {
7-
static function staticFunction() {
11+
static function staticFunction():Dynamic {
812
throw 'Thrown from static';
913
}
1014

@@ -65,4 +69,40 @@ class LocalFunctionExceptions {
6569

6670
return Error("No exception caught");
6771
}
72+
73+
public static function testObjMethodOnReturn():Status {
74+
function localFunction() {
75+
(staticFunction() : Dynamic).run();
76+
}
77+
78+
try {
79+
localFunction();
80+
} catch (e:String) {
81+
if (e == 'Thrown from static') {
82+
return Ok;
83+
} else {
84+
return Error("Incorrect exception caught from local function call: " + e);
85+
}
86+
}
87+
88+
return Error("No exception caught");
89+
}
90+
91+
public static function testClassMethodOnReturn():Status {
92+
function localFunction() {
93+
(staticFunction() : DummyClass).run();
94+
}
95+
96+
try {
97+
localFunction();
98+
} catch (e:String) {
99+
if (e == 'Thrown from static') {
100+
return Ok;
101+
} else {
102+
return Error("Incorrect exception caught from local function call: " + e);
103+
}
104+
}
105+
106+
return Error("No exception caught");
107+
}
68108
}

0 commit comments

Comments
 (0)