[lua] Add regression test for pcall return wrapping#12740
Conversation
| return -1; | ||
| } | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
For this function, haxe currently generates:
___Main_Main_Fields_.returnInTryCatch = function(x)
local _hx_status, _hx_result = pcall(function()
if (x > 0) then
do return x * 2 end;
end;
return _hx_pcall_default
end)
if not _hx_status then
local _g = _hx_result;
return -1;
elseif _hx_result ~= _hx_pcall_default then
return _hx_result
end;
return 0
endfrom what I can tell in this case the do end doesn't make much of a difference?
| eq(10, returnInTryCatch(5)); | ||
| eq(0, returnInTryCatch(-1)); | ||
|
|
||
| // Tail return should not use do...end wrapper |
There was a problem hiding this comment.
This test doesn't really do much, because even if there is a do ... end it's still going to pass. It's most useful to test if there is a case where the compiler missing out do ... end would result in broken output.
There was a problem hiding this comment.
Good point — rewrote the test to exercise actual pcall return propagation edge cases instead. Now covers returning null/false/zero through pcall (must not be confused with _hx_pcall_default sentinel), fall-through where try body has no return (code after try-catch must execute), nested try-catch, try-catch in loops, and exception handling paths.
Tests that return inside try-catch still uses do...end wrapper (since pcall callback has appended return _hx_pcall_default), while tail returns use bare return.
5d8a46e to
90ca592
Compare
Address review feedback: old test had returns inside if-blocks where do...end wrapping was redundant and tests passed either way. New test covers null/false/zero return propagation through pcall, fall-through vs return distinction via _hx_pcall_default sentinel, nested try-catch, try-catch in loops, and exception handling paths.
Summary
Issue7350) for thein_pcallguard that ensuresdo return endwrapping is preserved inside try-catch blocks (pcall callbacks), where the compiler appendsreturn _hx_pcall_defaultafter user code.returnwithout wrapping.Test plan
make haxebuilds successfully