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 alias keyword 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

@@ -6980,6 +6980,9 @@
69806980 if mname == "home" || mname == "pwd" || mname == "getwd"
69816981 return "string"
69826982 end
6983+ if mname == "exist?"
6984+ return "bool"
6985+ end
69836986 end
69846987 if rcname == "Integer"
69856988 if mname == "sqrt"
@@ -9719,6 +9722,18 @@
97199722 collect_class_method_alias(ci, nn, on)
97209723 end
97219724 end
9725+ # `alias_method :new, :old` -- the method-call form of `alias`.
9726+ # Same effect: copy the source method's slot under the new name.
9727+ if @nd_type[sid] == "CallNode" && @nd_receiver[sid] < 0 && @nd_name[sid] == "alias_method"
9728+ am_args = get_args(@nd_arguments[sid])
9729+ if am_args.length == 2
9730+ nn_am = symbol_node_literal(am_args[0])
9731+ on_am = symbol_node_literal(am_args[1])
9732+ if nn_am != "" && on_am != ""
9733+ collect_class_method_alias(ci, nn_am, on_am)
9734+ end
9735+ end
9736+ end
97229737 if @nd_type[sid] == "UndefNode"
97239738 # `undef foo, bar` -- record the removal in @undef_*. Spinel
97249739 # doesn't currently enforce "calling an undef'd method