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
interface Greet { def sayHello(): Unit }
def main() = {
var f = box { () }
try { f = box { g.sayHello() } }
with g: Greet { def sayHello() = println("hello!") }
f()
}
This should of course fail at compile-time since at the call-site of f, the capture g is not in scope. However, it fails with the following error at runtime:
Prompt 2 not found
The type of f is inferred as () => Unit at { g }. Thus, the first assignment is also valid due to capture subtyping. If you actually try to annotate it like this, you cannot since g is not in scope (TIL this is called a Voldemort type according to @jiribenes)
If you instead annotate f with the type of its first assignment, the program expectedly fails at compile-time:
interface Greet { def sayHello(): Unit }
def main() = {
var f: () => Unit at {} = box { () }
try { f = box { g.sayHello() } }
with g: Greet { def sayHello() = println("hello!") }
f()
}
The text was updated successfully, but these errors were encountered:
Consider this program:
This should of course fail at compile-time since at the call-site of
f
, the captureg
is not in scope. However, it fails with the following error at runtime:The type of
f
is inferred as() => Unit at { g }
. Thus, the first assignment is also valid due to capture subtyping. If you actually try to annotate it like this, you cannot sinceg
is not in scope (TIL this is called a Voldemort type according to @jiribenes)If you instead annotate
f
with the type of its first assignment, the program expectedly fails at compile-time:The text was updated successfully, but these errors were encountered: