Merge pull request 'fix(compiler): 修复 finally 使用变量' (#12) from fix-finally-use-var into master
Reviewed-on: #12pull/14/head
commit
f1f2e7e5cb
5 changed files with 167 additions and 14 deletions
@ -0,0 +1,30 @@ |
||||
--TEST-- |
||||
exception thrown inside catch is not handled by sibling catch |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class FinallySiblingA extends Exception {} |
||||
class FinallySiblingB extends Exception {} |
||||
|
||||
function main(): void |
||||
{ |
||||
try { |
||||
try { |
||||
throw new FinallySiblingA("a"); |
||||
} catch (FinallySiblingA $e) { |
||||
echo "catch-a\n"; |
||||
throw new FinallySiblingB("b"); |
||||
} catch (FinallySiblingB $e) { |
||||
echo "catch-b\n"; |
||||
} finally { |
||||
echo "finally\n"; |
||||
} |
||||
} catch (FinallySiblingB $e) { |
||||
echo "outer:" . $e->getMessage() . "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
catch-a |
||||
finally |
||||
outer:b |
||||
@ -0,0 +1,26 @@ |
||||
--TEST-- |
||||
finally must not see variables from unmatched catch clauses |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class FinallyUnmatchedA extends Exception {} |
||||
class FinallyUnmatchedB extends Exception {} |
||||
|
||||
function main(): void |
||||
{ |
||||
try { |
||||
try { |
||||
throw new FinallyUnmatchedA("a"); |
||||
} catch (FinallyUnmatchedB $e) { |
||||
echo "catch-b\n"; |
||||
} finally { |
||||
echo isset($e) ? "set\n" : "unset\n"; |
||||
} |
||||
} catch (FinallyUnmatchedA $e) { |
||||
echo "outer:" . $e->getMessage() . "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
unset |
||||
outer:a |
||||
@ -0,0 +1,26 @@ |
||||
--TEST-- |
||||
finally can use caught exception variable when catch rethrows |
||||
--FILE-- |
||||
<?php |
||||
|
||||
function main(): void |
||||
{ |
||||
try { |
||||
$a = 1; |
||||
throw new RuntimeException('test'); |
||||
return; |
||||
} catch (Throwable $e) { |
||||
echo 'Caught exception: ', $e->getMessage(), "\n"; |
||||
throw $e; |
||||
} finally { |
||||
var_dump($a); |
||||
echo 'Finally exception: ', $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Caught exception: test |
||||
int(1) |
||||
Finally exception: test |
||||
|
||||
Fatal error: Uncaught RuntimeException: test in %A |
||||
@ -0,0 +1,31 @@ |
||||
--TEST-- |
||||
multi-catch conditions respect catch match state with finally |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class FinallyMultiCatchA extends Exception {} |
||||
class FinallyMultiCatchB extends Exception {} |
||||
class FinallyMultiCatchC extends Exception {} |
||||
|
||||
function main(): void |
||||
{ |
||||
try { |
||||
try { |
||||
throw new FinallyMultiCatchA("a"); |
||||
} catch (FinallyMultiCatchA|FinallyMultiCatchB $e) { |
||||
echo "catch-ab\n"; |
||||
throw new FinallyMultiCatchC("c"); |
||||
} catch (FinallyMultiCatchC $e) { |
||||
echo "catch-c\n"; |
||||
} finally { |
||||
echo "finally\n"; |
||||
} |
||||
} catch (FinallyMultiCatchC $e) { |
||||
echo "outer:" . $e->getMessage() . "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
catch-ab |
||||
finally |
||||
outer:c |
||||
Loading…
Reference in new issue