jakt icon indicating copy to clipboard operation
jakt copied to clipboard

REPL: Weak pointers don't point to None when pointee hits end of scope

Open ADKaster opened this issue 3 years ago • 2 comments

Running samples/weak/basic.jakt produces different results for comptime vs build time execution, suggesting that either foo is not destroyed at the end of the scope, or the weak pointer is not updated:

class Foo {
    public function hello(this) => "friends"
}

function main() {
    mut weak_foo: weak Foo? = None

    println("weak_foo has_value? {}", weak_foo.has_value())

    {
        let foo = Foo()
        weak_foo = foo

        println("weak_foo has_value? {}", weak_foo.has_value())
        println("weak_foo hello: {}", weak_foo!.hello())
    }

    println("weak_foo has_value? {}", weak_foo.has_value())
}
~/jakt$ ./build/bin/jakt -r samples/weak/basic.jakt
weak_foo has_value? false
weak_foo has_value? true
weak_foo hello: friends
weak_foo has_value? true <------ !!!!
~/jakt$ ./build/bin/jakt -cr samples/weak/basic.jakt
weak_foo has_value? false
weak_foo has_value? true
weak_foo hello: friends
weak_foo has_value? false

ADKaster avatar Sep 03 '22 10:09 ADKaster

This is expected because WeakPtr::has_value() is not implemented for comptime.

At the same time, this is unexpected because WeakPtr::has_value() is not implemented for comptime. It should fail to parse/compile the code with -r

ADKaster avatar Sep 03 '22 10:09 ADKaster

I think this is just because the interpreter doesn't actually perform the implicit casts required for our weakptr mess to work, so it's seen as an Optional instead.

alimpfard avatar Sep 03 '22 10:09 alimpfard