8000 Overloaded call with an untyped argument is resolved by guess and runs the wrong overload · Issue #643 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Overloaded call with an untyped argument is resolved by guess and runs the wrong overload #643

Closed

Description

@akoskovacs

When a function with several overloads is called with an argument whose type is not known yet, the checker picks one overload and types the argument from it. The call is then resolved to that overload for every caller.

Repro

let describe(n: Integer) -> String = "integer ${n}"
let describe(s: String) -> String = "string ${s}"

let show(x) = describe(x)

main do
  IO.printLine(show(1))
  IO.printLine(show(2.5))
end

Actual: accepted; prints integer 1 and then string 2.5. A Float reached the String overload.

Expected: either an error at describe(x) asking for an annotation on x (several overloads, argument type unknown), or show(2.5) rejected because no overload takes a Float. It should never run the wrong overload.

Cause

After an overload is chosen, checkCall binds a still-unknown argument to the winner's parameter type (src/semantic/typechecker_expr.cxx:5914-5936; the receiver case is tracked in m_guessedReceiverTypes). With one candidate that is inference; with several it is a guess.

Reproduced on kex 0.4.0-rc.3 (266b7a60) with the type checker on.

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

    BugSomething isn't workingConfirmed IssueBug is reproduced on the current development versionTypechecker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0