Skip to content

Commit

Permalink
Make ternary and support for distinct types, fixes #234
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Nov 1, 2023
1 parent cd6986b commit 20d784a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion lualib/nelua/cgenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,6 @@ function visitors.BinaryOp(context, node, emitter, untypedinit)
emitter:add_zeroed_type_literal(type)
emitter:add_ln(';')
if opname == 'and' then
assert(not attr.ternaryand)
emitter:add_indent(primtypes.boolean, ' cond_ = ')
emitter:add_val2boolean('t1_', type)
emitter:add_ln(';')
Expand Down
8 changes: 8 additions & 0 deletions spec/cgenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,14 @@ it("binary conditional operators", function()
assert((false and false or true) == true)
assert((false and false or false) == false)
assert(('' and true or false) == true)
assert((0 and true or false) == true)
assert((false and true or false) == false)
assert((true and false or true) == true)
assert((nil and false or true) == true)
assert((niltype and false or true) == true)
assert((niltype and 'true' or 'false') == 'true')
assert((false and 1 or 2) == 2)
assert((true and 1 or 2) == 1)
-- assert((true and 1 and 2 or 3) == 2)
Expand Down

0 comments on commit 20d784a

Please sign in to comment.