A make-block method with defaulted parameters hijacks same-named calls on other receivers ("undefined function string/5") · Issue #475 · kexhq/kex · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A make-block method with defaulted parameters hijacks same-named calls on other receivers ("undefined function string/5") #475
Since #473, a make-block method that has defaulted parameters takes over other calls of the same method name on unrelated receivers, and those calls compile to an arity that does not exist.
Reproduce (one file)
record Builder do
table : String = ""
end
make Builder do
let string(label: Atom, primaryKey: Bool = false, nullable: Bool = false) -> String do
"${label} ${primaryKey} ${nullable}"
end
end
main do
IO.printLine(Builder {}.string(:id, primaryKey: true))
let parsed = URI.parse("https://example.com/a?b=1").try
IO.printLine(parsed.string)
end
kex_a: undefined function string/3 in main/0
error: erlc failed
Either change makes it compile and print :id true false and the URL:
rename the method (column instead of string), or
remove the defaults and pass every argument.
In a real program
With a table builder whose string has four defaulted options, any program that also links Rodolfo fails inside the standard library's own module:
Kex.URI: undefined function string/5 in 'equivalent?/URI'/2
Kex.URI: undefined function string/5 in 'equivalent?/URL'/2
And two make-block methods of one name in different records, one of them with defaults, confuse each other. TableBuilder.text(label, primaryKey: Bool = false, …) beside Definition.text(name: Atom):
runtime error: Undefined method: text for Harmat.Table.Definition
(the type checker accepts all of these).
Where
makeMethodFor in src/ir/lower.cxx. When the receiver's type is known but declares no such method in this unit, the non-strict path retries with no owner at all:
so parsed.string (receiver URI) binds Builder.string, and placeMethodArguments then fills the "missing" parameters from Builder.string's defaults. A receiver whose type is known and is not the method's owner should not be bound to it.
Impact
This is what stops t.string(:name, default: :null, nullable: true) — the form #473 set out to make possible — from being used in an application: Harmat's builder method had to be named text, and its unrelated column handles renamed away from text.
Activity
Builder text columns are t.text; column handles are textColumn/wholeC…