Commit 955516b6
955516b668f5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Fix Symbol#id2name typing, RUBY_DESCRIPTION, and Range#minmax
Three small gaps surfaced by the audit batch:
- Symbol#id2name: codegen already routed it to sp_sym_to_s, but
analyze mis-typed the result as int, so the symbol id printed
instead of the name. Type it
string(alias of #to_s). - RUBY_DESCRIPTION: was an undefined constant (read back as a non- String). Provide it as a String alongside RUBY_VERSION / _ENGINE / _PLATFORM.
- Range#minmax: materialize [min, max] as a 2-element int_array ([first, last - excl]); previously the unhandled call fell through to a Range struct in an mrb_int context (C error).
:hello.id2name # => "hello" (was: the raw symbol id) RUBY_DESCRIPTION.class # => String (was: not a String) (1...10).minmax # => [1, 9] (was: compile error)
Fixes #1249 Fixes #1251 Fixes #1217
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 955516b668f5
- Parent
- f1b5229f4adf
spinel_analyze.rbmodifiedView file
@@ -2490,7 +2490,7 @@
24902490
end24912491
# Issue #890: RUBY_VERSION / RUBY_PLATFORM / RUBY_ENGINE are24922492
# built-in string constants provided by the runtime.2493-
if @nd_name[nid] == "RUBY_VERSION" || @nd_name[nid] == "RUBY_PLATFORM" || @nd_name[nid] == "RUBY_ENGINE"2493+
if @nd_name[nid] == "RUBY_VERSION" || @nd_name[nid] == "RUBY_PLATFORM" || @nd_name[nid] == "RUBY_ENGINE" || @nd_name[nid] == "RUBY_DESCRIPTION"24942494
return "string"24952495
end24962496
rname = resolve_const_read_name(@nd_name[nid])@@ -4424,6 +4424,12 @@
44244424
# Class#name -- the class's source name as44254425
# a string. Aliases `.to_s` at the runtime helper level44264426
# (sp_class_to_s), so the return type is the same.4427+
# Symbol#id2name is an alias for #to_s: the symbol's name as a String.4428+
# Codegen already routes it to sp_sym_to_s; without this the result4429+
# mis-types to int and prints the raw symbol id.4430+
if mname == "id2name" && recv >= 0 && infer_type(recv) == "symbol"4431+
return "string"4432+
end44274433
if mname == "name"44284434
if recv >= 0 && infer_type(recv) == "encoding"44294435
return "string"@@ -5518,6 +5524,11 @@
55185524
if mname == "minmax"55195525
if recv >= 055205526
rt = infer_type(recv)5527+
# A Range materializes [min, max] as a 2-element int_array (codegen5528+
# builds it from .first / .last - .excl).5529+
if rt == "range"5530+
return "int_array"5531+
end55215532
et = elem_type_of_array(rt)55225533
return "tuple:" + et + "," + et55235534
endspinel_codegen.rbmodifiedView file
Loading diff…
test/symbol_id2name_ruby_desc_minmax.rbaddedView file
Loading diff…
test/symbol_id2name_ruby_desc_minmax.rb.expectedaddedView file
Loading diff…