-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: invalid type for const: T
prevents default initializing at compile time when T has a reference field
#8521
Comments
I'm very surprised that # Works fine
static:
var a: ref int
new(a)
a[] = 1
echo a[] |
I think this makes sense, right? You cannot have a constant reference, the actual address will be unknown until runtime. You can do this in the case of nil, although I am not sure how useful this is |
Error: invalid type for const: T
prevents default initializing at compile time when T has a reference fieldError: invalid type for const: T
prevents default initializing at compile time when T has a reference field
when |
It's useful for generic programming. And yes, the value should obviously be nil, but it doesn't compile. |
No, it makes no sense to support every type |
the problem is when a type |
EDIT: just added a new test case (see |
@timotheecour I think proc foo =
var val {.compileTime.} = 1 It looks like proc defaultImpl[T]():T=
var a: T
return a
type App = object
a: ref int
var val {.compileTime.} = defaultImpl[App]()
static:
echo val |
"Error: invalid type for const: App" is a good error message and works as designed. Closing. |
/cc @Araq
This is a blocker for doing compile time reflection (and doing many things that rely on it). Any chance this could be fixed?
it also limits fix #8485 ; make
default
public instead of redefined everywhere; use better implementation #8490EDIT it's also inconsistent with the fact that this works:
(
seq
andstring
are reference types)The text was updated successfully, but these errors were encountered: