awestlake87/helix

references

Opened this issue · 0 comments

references will work a bit differently than in C++. although they cannot be default constructed or directly assigned nil, they will be closer to pointers. I'll see how this plays out when rewriting metac and determine if this is the behavior I want.

fun take_a_ref(&int a):
    a = 12

fun take_a_ptr(*int a):
    *a = 12

i: int(0)

// functions that take ptrs or refs are called in the same way
take_a_ref(&i)
take_a_ptr(&i)

// this will be a compiler error
take_a_ref(nil)
// this will work
take_a_ptr(nil)

i_ptr: &i

// this is fine
take_a_ref(i_ptr)
// this is also fine
take_a_ptr(i_ptr)

i_ref: &auto(i_ptr)

take_a_ref(i_ref)
// references do not decay into pointers
take_a_ptr(&i_ref)