8000 A make-block method with defaulted parameters hijacks same-named calls on other receivers ("undefined function string/5") · Issue #475 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

A make-block method with defaulted parameters hijacks same-named calls on other receivers ("undefined function string/5") #475

Closed

Description

@akoskovacs

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:

return strict || owner.empty() ? nullptr : makeMethodFor(n, "", false);

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.

Environment: Kex 0.4.0-rc.1 (66ec75c), Erlang/OTP 29.0.5, macOS arm64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BEAMBugSomething isn't workingImportantNeeds attention sooner rather than later

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0