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
Function call on an unconstrained type parameter is accepted #646
Inside a generic make block, calling a function on a value of an unconstrained type parameter is accepted, whatever the function is. The call fails at run time for any type argument that does not have it.
Repro
trait Pretty do
pretty :> String
end
make Integer, implement: Pretty do
let pretty = "#${this}"
end
record Box<T> do
item : T
end
make Box<T>, implement: Pretty do
let pretty = "Box(${@item.pretty})"
end
let render(p: Pretty) -> String = p.pretty
main do
IO.printLine(render(Box { item: 1 }))
IO.printLine(render(Box { item: "no Pretty for String" }))
end
Actual: accepted; prints Box(#1), then fails at run time with Undefined method: pretty for String.
Expected: one of
an error at @item.pretty, since nothing says T has pretty, or
an error at the second render call, since Box<String> is not Pretty.
Notes
Two things combine here:
A call on an unconstrained T is not checked.
A trait implementation is recorded under the type's name alone, so Box counts as Pretty for every T.
The first can be rejected today. Making the example expressible (Box<T> is Pretty when T is) needs a way to write a bound on T, which is a language decision.
Reproduced on kex 0.4.0-rc.3 (266b7a60) with the type checker on.
Activity