Commit c6fbf9ca
c6fbf9ca1ebeMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #358 from mame/pr/argv-default-narrow-from-call-site
fix(codegen): narrow ARGV-default param from single-string call site
Details
- Commit
- c6fbf9ca1ebe
- Parent
- 10a72a329eac
- Merge parent
- 117d73c9d86c
spinel_codegen.rbmodifiedView file
@@ -9858,6 +9858,16 @@
98589858
if (old_pt == "float" && at == "int") || (old_pt == "int" && at == "float")98599859
return "float"98609860
end9861+
# `def f(conf = ARGV)`: the default's type lands as `argv`9862+
# (spinel's specialised `**argv`-like scalar), but bootstrapping9863+
# callers in real programs almost always invoke `f("path.nes")`9864+
# — a single string. Without this narrow, unification falls to9865+
# poly and the body's `Config.new(conf)` (string-expecting) gets9866+
# a poly arg. Bias toward the call-site shape so single-string9867+
# entry points don't drag the whole signature into poly.9868+
if (old_pt == "argv" && at == "string") || (old_pt == "string" && at == "argv")9869+
return "string"9870+
end98619871
# Genuinely incompatible types: fall back to polymorphic value.98629872
@needs_rb_value = 198639873
"poly"test/default_argv_narrows_from_string_call_site.rbaddedView file
Loading diff…
test/default_argv_narrows_from_string_call_site.rb.expectedaddedView file
Loading diff…