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
Annotated type variables are not rigid: a body can specialise its own signature #644
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