ModularM
Modular15mo ago
41 replies
ivellapillil

Preserving mutability when passing to function

How to make pointer passed to a function preserve/transmit its mutability?
    var a_instance = A(12)
    var ref_a = Pointer.address_of(a_instance) 
    
    def change_value(p: Pointer[A]):
        p[] = 15 # <- Error 

    change_value(ref_a)
    ref_a[] = 15 # Works


Or is it a conscious constraint on Pointer and we should use UnsafePointer or Arc here?
Was this page helpful?