Commit ead258d2
ead258d27f8dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Implement Dir.exist? and alias_method dispatch
Two dispatch gaps reported in #1233:
-
Dir.exist?(path) was unresolved (the Dir receiver inferred as int). Infer it as bool and emit sp_file_directory, since Dir.exist? is true iff the path is a directory. Dir.exists? is deliberately not added: modern Ruby removed it (raises NoMethodError), and spinel matches the documented CRuby API.
-
alias_method :new, :old on a user class silently dropped the new name. The
aliaskeyword form (AliasMethodNode) already worked via the class body's third collection pass; route the method-call form (a receiverless CallNode named alias_method) through the same collect_class_method_alias, reusing symbol_node_literal for the names.
define_method (the issue's third item) already worked.
Closes #1233
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- ead258d27f8d
- Parent
- bd080d657147
spinel_analyze.rbmodifiedView file
if mname == "home" || mname == "pwd" || mname == "getwd" return "string" end if mname == "exist?" return "bool" end end if rcname == "Integer" if mname == "sqrt" collect_class_method_alias(ci, nn, on) end end # `alias_method :new, :old` -- the method-call form of `alias`. # Same effect: copy the source method's slot under the new name. if @nd_type[sid] == "CallNode" && @nd_receiver[sid] < 0 && @nd_name[sid] == "alias_method" am_args = get_args(@nd_arguments[sid]) if am_args.length == 2 nn_am = symbol_node_literal(am_args[0]) on_am = symbol_node_literal(am_args[1]) if nn_am != "" && on_am != "" collect_class_method_alias(ci, nn_am, on_am) end end end if @nd_type[sid] == "UndefNode" # `undef foo, bar` -- record the removal in @undef_*. Spinel # doesn't currently enforce "calling an undef'd methodspinel_codegen.rbmodifiedView file
Loading diff…
test/alias_method_dispatch.rbaddedView file
Loading diff…
test/dir_exist.rbaddedView file
Loading diff…