8000 A union argument is rejected by an overloaded function that covers every member · Issue #647 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

A union argument is rejected by an overloaded function that covers every member #647

Closed

Description

@akoskovacs

A value of a union type cannot be passed to an overloaded function, even when there is an overload for every member of the union.

Repro

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

let label(id: Integer | String) -> String = describe(id)

main do
  IO.printLine(label(3))
end

Actual:

error: `describe` expects argument 1 to be Integer, but got Integer | String

describe : Integer -> String

describe : String -> String

Expected: accepted, dispatching on the value at run time, with the result typed as the join of the overloads' results (String here).

Notes

Each overload is tried against the whole union, and a union only flows to a parameter when every member fits it. Overload resolution has no step that covers the union member by member.

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