Commit 05f4040b
05f4040b531cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(codegen,analyze): .encoding stub + Rational/Complex graceful fallback
#723 (.encoding): spinel doesn't model Encoding objects, but the
warning "cannot resolve call to 'encoding' on string (emitting 0)"
made puts print the literal 0. Now compile_call returns a plain
"UTF-8" const char* and infer_type returns "string", so puts s.encoding prints "UTF-8" -- matching the implicit invariant that
spinel treats all source as UTF-8 anyway.
#728 (Rational / Complex / Imaginary): RationalNode + ComplexNode
used to hard-exit ("Spinel: cannot compile RationalNode at line N"
followed by exit(1)), preventing the rest of the file from
compiling at all. Switch to a soft fallback: warn + emit 1
(integer). 1 -- not 0 -- so the very common N / Mr shape
doesn't turn into a runtime divide-by-zero. Result is still wrong
arithmetic for the literal but the program continues; users
unintentionally hitting one of these literals get a clear warning
instead of a build failure. compile_stmt mirrors the same softer
path (warn + no-op).
Tests: test/string_encoding.rb covers the three .encoding entry points (plain, after .encode, after .b).
462 tests pass; optcarrot checksum 59662.
Closes #723 Closes #728
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 05f4040b531c
- Parent
- 662525bbe536
spinel_analyze.rbmodifiedView file
# colliding with user-defined methods of the same name (`b` is # the shortest collision target; struct field accessors etc. # commonly take that single-letter shape). if mname == "encoding" # spinel doesn't model Encoding objects; treat the return as a # plain string label (`"UTF-8"`). Issue #723. if recv >= 0 rt_enc = infer_type(recv) if rt_enc == "string" || rt_enc == "mutable_str" return "string" end end end if mname == "force_encoding" || mname == "encode" || mname == "b" if recv >= 0 rt_fe = infer_type(recv)spinel_codegen.rbmodifiedView file
Loading diff…
test/string_encoding.rbaddedView file
Loading diff…
test/string_encoding.rb.expectedaddedView file
Loading diff…