8000 Annotated type variables are not rigid: a body can specialise its own signature · Issue #644 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Annotated type variables are not rigid: a body can specialise its own signature #644

Open

Description

@akoskovacs

A single-letter type variable in a signature promises that the function works for any type. Inside the body the checker treats it as an ordinary inference variable, so the body can pick a type for it.

Repro

let same(a: A) -> A = 1

main do
  IO.printLine(same("hello"))
end

Actual: accepted; prints 1. A String went in and an Integer came out of A -> A.

Expected: an error on same: declared to return A, but the body returns Integer.

Cause

  • An annotated type variable is created as a fresh flexible variable (src/semantic/typechecker.cxx:2905-2910).
  • The return check is skipped when the declared result is a type variable (typechecker.cxx:4065).
  • argMatchesParam accepts whenever either side is still open.

The variables written in a signature need to be rigid while that function's body is checked: not bindable, and matching only themselves. Call sites would keep instantiating them as they do now.

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

Activity

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