[bitc-dev] ref to union contents
digitale at digitaleric.net
Mon Mar 7 16:26:01 EST 2005
It has occurred to me that the ability to take references to objects combined with the BitC's tagged unions might be dangerous. Can we take references to the contents of a union? It would be nice if we could, safely. On the other hand, if the union is mutable, it is important that programs not be able to keep references to the contents of the union past the assignment. Because the assignment might change which leg of the union is being used.
The following program probably isn't correct BitC 0.6, but I hope it conveys the hypothetical problem scenario.
(b . . .))
(define x:(mutable foo)
(let (r (ref int_from_a))
(set! x (b (. . .)))
do_something gets a reference to int_from_a, even though x is no longer in the 'a' branch of the union.
Reading the 0.6 BitC spec, I don't anything making this illegal. And it doesn't seem that the (let (r (ref int_from_a))) does a copy of int_from_a. So the above code should be illegal. Have I missed something?
More information about the bitc-dev