PlutoLang / Pluto

A superset of Lua 5.4 with a focus on general-purpose programming.
https://pluto-lang.org/docs/Introduction
MIT License
338 stars 20 forks source link

If expression does not work in const if statement #800

Closed XmiliaH closed 2 months ago

XmiliaH commented 2 months ago

The skip_block function used for the const if statement cannot handle the if expression since it expects it to end with end which it does not.

$if false then
    local x = if a then b else c
$else
    local x = 2
$end
Sainan commented 2 months ago

Part of me wonders if we should even continue to support the if-expression. I have no data as for the prevalence of it, especially considering Lua forks other than Pluto, but I can't imagine it's worthwhile in the slightest when most people either don't use it or use the compact ternary expression. @well-in-that-case Thoughts?

well-in-that-case commented 2 months ago

Part of me wonders if we should even continue to support the if-expression. I have no data as for the prevalence of it, especially considering Lua forks other than Pluto, but I can't imagine it's worthwhile in the slightest when most people either don't use it or use the compact ternary expression. @well-in-that-case Thoughts?

The documented purpose of the alternative ternary syntax is legacy compatibility with older Pluto versions. Much time has passed since then, so considering deprecation would not be unreasonable. However, I don't view this syntax as a burden either.

Sainan commented 2 months ago

For cases like this, it kind of is a burden, but for the $if statement, we can specialize for the '$'. That at least resolves this bug on 0.10.0.