Lifetime is incorrectly inferred as dead
As pointed out in the chat, sometimes the lifetime inferrence will infer that an alive reference is dead. Here’s an example of the bug and a workaround in the test code for URI.
The good news is that this seems to happen pretty rarely, and can be fixed by hoisting an inline reference into a containing let statement. It should still be fixed, of course.
Cheers
Is there a small reproducible for this?
I just tried coming up with one, but failed. The best I can offer is this:
(load "Test.carp")
(use Test)
(load "[email protected]:carpentry-org/[email protected]")
(def uri "scheme://usr:[email protected]:123/path?query=1#fragment")
(deftest test
(assert-equal test
uri
&(str &(Result.unsafe-from-success (URI.parse uri)))
"we can convert our representation to a string again correctly"
)
)
Which depends on the URI library. Sorry about that!
There’s also a problem using System.get-arg:
(defn main []
(for [i 0 (System.get-args-len)]
(let [x (System.get-arg i)] ; this is inferred as dead
(if (ends-with? x "Untitled")
(println* x)
()))))
I assume that the Ref there should have a static lifetime, but I’m not sure how to annotate that.