fxm wrote: ↑Mar 04, 2023 14:31
But what about getting an error message for the following code (with or without a constructor)?
What I was kind of saying in my last post:
Passing temporary type to function not a problem on it's own, because function could be:
Code: Select all
function f( byref x as T ) byref as T
static value as T = 0
value = x
return value
end function
scope
'' this is OK because function returns a reference with longer lifetime than this scope
dim byref as T ref = f(type<T>(123))
end scope
And in the function, returning an argument by reference not a problem on it's own, because caller could be:
Code: Select all
function f( byref x as T ) byref as T
return x
end function
scope
dim as T arg = type<T>(123)
dim byref as T ref = f(arg)
'' this is OK because ref is valid until end of scope
end scope
Only when we have the two together - passing a temporary type to a function that returns the argument as a byref result.
I don't know how we could detect that.