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
if (old_pt == "float" && at == "int") || (old_pt == "int" && at == "float") return "float" end # `def f(conf = ARGV)`: the default's type lands as `argv` # (spinel's specialised `**argv`-like scalar), but bootstrapping # callers in real programs almost always invoke `f("path.nes")` # — a single string. Without this narrow, unification falls to # poly and the body's `Config.new(conf)` (string-expecting) gets # a poly arg. Bias toward the call-site shape so single-string # entry points don't drag the whole signature into poly. if (old_pt == "argv" && at == "string") || (old_pt == "string" && at == "argv") return "string" end # Genuinely incompatible types: fall back to polymorphic value. @needs_rb_value = 1 "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…