epatrizio / ola

OCaml Lua Interpreter
The Unlicense
1 stars 1 forks source link

Bug return statement #10

Closed epatrizio closed 11 months ago

epatrizio commented 1 year ago

3.3.4 – Control Structures (official documentation) https://www.lua.org/manual/5.4/manual.html#3.3.4

The return statement can only be written as the last statement of a block. If it is necessary to return in the middle of a block, then an explicit inner block can be used, as in the idiom do return end, because now return is the last statement in its (inner) block.

-- Actually, when return isn't at the end of the block, the stop is still made at this point.

epatrizio commented 11 months ago

Check block definition in parser https://github.com/epatrizio/ola/blob/main/src/parser.mly In PR mentioned above (parser full refactoring), return can only be written as the last block statement. Otherwise it causes a syntax error. Check line 76 https://github.com/epatrizio/ola/blob/main/test/blocks.lua

epatrizio commented 11 months ago

https://github.com/epatrizio/ola/commit/96f0806f446497efa27142cf06af446d3e201406

epatrizio commented 11 months ago

related issue #7