Carp
Carp copied to clipboard
Borrow checker is confused by using a match-ref with a let block
The following code produces a borrow checker error even though there is no shared values between the two match-ref:
(deftype Sum One Two)
(defn main []
(do
(let []
(match-ref &(Sum.One)
Sum.One ()
Sum.Two ()))
(match-ref &(Sum.Two)
Sum.One ()
Sum.Two ())))
The reference '(ref (Sum.Two))' (depending on the variable '_9') isn't alive at line 9, column 15 in '/tmp/main.carp'. at /tmp/main.carp:3:1.
The following code works fine so it seems related to the scope of the let:
(deftype Sum One Two)
(defn main []
(do
(match-ref &(Sum.One)
Sum.One ()
Sum.Two ())
(match-ref &(Sum.Two)
Sum.One ()
Sum.Two ())))
This version has slightly more readable error message:
(deftype Sum One Two)
(defn main []
(let-do [sum-two (Sum.Two)]
(let [sum-one (Sum.One)]
(match-ref &sum-one
Sum.One ()
Sum.Two ()))
(match-ref &sum-two
Sum.One ()
Sum.Two ())))
The reference '(ref sum-two)' (depending on the variable 'sum_MINUS_one') isn't alive at line 9, column 15 in '/tmp/main.carp'. at /tmp/main.carp:3:1.