Commit f11d33c1
f11d33c1d34eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: Integer#ceil / floor / round / truncate without arg return self
Previously fell through the unresolved-call path and emitted 0. CRuby returns the receiver unchanged for integers; add the trivial self-return arm in compile_int_method_expr. The single-arg (precision) form has different semantics and is deferred to a follow-up.
Fixes #984
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- f11d33c1d34e
- Parent
- 626d9f7ddf22
spinel_codegen.rbmodifiedView file
@@ -20830,6 +20830,14 @@
2083020830
end2083120831
2083220832
def compile_int_method_expr(nid, mname, rc)20833+
# Integer#ceil / floor / round / truncate without precision arg20834+
# return self. With precision the CRuby semantics differ; defer20835+
# those to a follow-up.20836+
if mname == "ceil" || mname == "floor" || mname == "round" || mname == "truncate"20837+
if @nd_arguments[nid] < 0 || get_args(@nd_arguments[nid]).length == 020838+
return rc20839+
end20840+
end2083320841
# is_a? / kind_of? on a primitive int: resolve at compile time. The2083420842
# arg is a class constant (Integer / Numeric / Comparable / etc.);2083520843
# answer based on Ruby's class hierarchy. Anything not in the inttest/int_ceil_floor_round.rbaddedView file
Loading diff…
test/int_ceil_floor_round.rb.expectedaddedView file
Loading diff…