daScript icon indicating copy to clipboard operation
daScript copied to clipboard

if_ref not working for value types

Open spiiin opened this issue 2 years ago • 1 comments

looks like if_ref/is_ref_value not working for value types

options log_infer_passes=true
[export]
def main
    var a: int
    var b: int& = a

    print("{typeinfo(typename type<int&>)}\n")
    print("{typeinfo(is_ref type<int&>)}\n")
    print("{typeinfo(is_ref_value type<int&>)}\n")
    print("{typeinfo(is_ref_type type<int&>)}\n")
    print("\n")
    print("{typeinfo(typename b)}\n")
    print("{typeinfo(is_ref b)}\n")
    print("{typeinfo(is_ref_value b)}\n")
    print("{typeinfo(is_ref_type b)}\n")

//Output:
int&
true
true
false

int
false
false
false

spiiin avatar Jan 23 '23 13:01 spiiin

its an interesting case. i need to think about it - because both behaviors for local refs are viable

borisbat avatar Apr 30 '23 07:04 borisbat

the more i think about it, the more i think its correct behavior. we can add is_ref_variable if we ever encounter a case, where this distinction is necessary. so far just 'b' is correct to not b e a ref.

		print("{typeinfo(typename a)}\n")
		print("{typeinfo(is_ref a)}\n")
		print("{typeinfo(is_ref_value a)}\n")
		print("{typeinfo(is_ref_type a)}\n")

also prints int,false,false,false.

borisbat avatar Jun 29 '24 01:06 borisbat