You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ordBooleanImpl aliases unsafeCoerceImpl: compare on Boolean crashes under Lua 5.1 #10
For Int, Number, String and Char the < operator is well defined in Lua, so reusing the helper is fine. For Boolean it is not. Lua 5.1 (the pslua target) raises a runtime error on relational operators between booleans:
$ lua -e 'print(pcall(function() return false < true end))'
false (command line):1: attempt to compare two boolean values
So any use of Ord Boolean (compare, <, <=, min, max, clamp) crashes at runtime instead of returning an ordering. The bug stays silent until a program actually compares two booleans.
Fix
Give ordBooleanImpl its own implementation that orders false < true without relying on <:
A working implementation already exists in @UnrelatedString's #3. It will be carried over from there with credit as part of the upstream-sync pass. The other ord*Impl aliases are correct and should stay on the shared helper.
Test coverage
The fix must ship with a regression test that fails on the current alias and passes after the fix: assert compare false true == LT, compare true false == GT, compare true true == EQ, and that min/max on Boolean do not error. This belongs in the prelude test suite being revived during upstream-sync. Without it the crash can regress unnoticed, since luacheck does not exercise the comparison.
Activity
Unisay commentedon Jun 15, 2026
Fixed in v7.3.0: ordBooleanImpl maps booleans to 0/1 before comparing (no
<on booleans). Verified under Lua 5.1.