Commit 8afc7106
8afc7106f008Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Type TrueClass/FalseClass #& #| #^ as boolean
true & true inspected as 1 instead of true: the logical
operators on a boolean receiver were inferred as int. For two boolean
operands the codegen's bitwise op already produces the right 0/1
value, so only the result type needed correcting to bool.
Refs #1223
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 8afc7106f008
- Parent
- 7df75f7a1fb9
spinel_analyze.rbmodifiedView file
@@ -3834,6 +3834,13 @@
38343834
return "poly"38353835
end38363836
end3837+
# TrueClass / FalseClass logical operators yield a boolean, not an3838+
# int: `true & false` is `false`, `true ^ false` is `true`. For two3839+
# boolean operands the codegen's bitwise op already gives the right3840+
# 0/1 value; only the result type needed correcting.3841+
if lt == "bool" && (mname == "&" || mname == "|" || mname == "^")3842+
return "bool"3843+
end38373844
# Proc / lambda composition operators return another proc / lambda38383845
# of the same representation. `(f << g)` / `(f >> g)`.38393846
if (lt == "lambda" || lt == "proc") && (mname == "<<" || mname == ">>")test/bool_logical_operators.rbaddedView file
Loading diff…
test/bool_logical_operators.rb.expectedaddedView file
Loading diff…