Commit 117d73c9

117d73c9d86cMerged

Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): narrow ARGV-default param from single-string call site

def initialize(conf = ARGV) typed conf as the specialised argv scalar. Bootstrapping callers like Optcarrot::NES.new("rom.nes") then unified the call-site string against argv. Without an argv-vs-string rule the unifier dropped to the catch-all poly tail, widening conf to poly and miscompiling Config.new(conf) (which expects a String).

Add an explicit narrow at unification: argv + string → string. Biases toward the call-site shape so single-string CLI-style entry points don't drag the whole signature into poly. Genuine array-of-strings call sites still hit the existing array-array unification path, untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
117d73c9d86c
Parent
01f36bc8ec7a

spinel_codegen.rbmodifiedView file

@@ -9758,6 +9758,16 @@
97589758 if (old_pt == "float" && at == "int") || (old_pt == "int" && at == "float")
97599759 return "float"
97609760 end
9761+ # `def f(conf = ARGV)`: the default's type lands as `argv`
9762+ # (spinel's specialised `**argv`-like scalar), but bootstrapping
9763+ # callers in real programs almost always invoke `f("path.nes")`
9764+ # — a single string. Without this narrow, unification falls to
9765+ # poly and the body's `Config.new(conf)` (string-expecting) gets
9766+ # a poly arg. Bias toward the call-site shape so single-string
9767+ # entry points don't drag the whole signature into poly.
9768+ if (old_pt == "argv" && at == "string") || (old_pt == "string" && at == "argv")
9769+ return "string"
9770+ end
97619771 # Genuinely incompatible types: fall back to polymorphic value.
97629772 @needs_rb_value = 1
97639773 "poly"