-
-
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
type Foo[T: static] = object
doesn't work; type Foo[T] = object
is buggy when instantiated with static generic arg
#13529
Comments
No. If you think why this should work please elaborate. If you want to pass static integers to types the declaration type is |
block:
type Foo[T] = object # accepts both types and (controversial) statics
echo Foo[float]
echo Foo[3] # currently accepted
block:
type Foo[T: seq] = object # only accepts seq[T] for some T
echo Foo[seq[int]]
block:
type Foo[T: array] = object # only accepts array[N,T] for some N,T
echo Foo[array[3,int]]
block:
type Foo[T: typedesc] = object # only accept `typedesc[T]` for some T
echo Foo[typedesc[float]]
echo Foo[float] # ok too, as expected
# echo Foo[3.1] # correctly gives CT error
block:
type Foo[T: static[float]] = object # only accept static[float]
# echo Foo[float] # correctly gives CT error
echo Foo[3.1] # ok: Foo[3.1]
block:
type Foo[T: static] = object # only accept static[T] for some T
# echo Foo[float] # correctly gives CT error
echo Foo[3.1] # BUG (this issue)
that's not generic, I need to accept any static[T] where T is a type, so that: Again, see #13433 (comment) |
now that #13976 was merged the only things left to fix is:
|
@timotheecour please update the issue description, or open a new followup issue and close this one. |
I've updated issue description |
|
type Foo[T: static] = object
doesn't work but should; EDIT: it should work liketype Foo[T: static type] = object
which does worktype Foo[T] = object
is buggy when instantiated with static generic argtype Foo[T: static type] = object
,var a: Foo[int]
should not compile (var b: Foo[3]
does and should)type Foo[T] = object
(controversial because potential breaking change, eg forarray[N,T]
) should probably not accept static inputs (eg var foo: Foo[1.2]) but we should have a way to have both, eg:type Foo[T: static|typedec] = object
Example 1:
type Foo[T] = object
is buggy when instantiated with static generic argexample from #13433 (comment) /cc @zah
Current Output
Expected Output
should not compile
Example 2:
type Foo[T: static] = object
doesn't worknote
type Foo[T: static type] = object
does work when instantiating with static generic argsExample 3
should this compile? or should it require
type Foo[T: static] = object
(Which currently doesnt' work)IMO it should not compile, but it may be useful to have a typeclass that encompasses both types and static, eg:
[T: static | typedesc]
Additional Information
EDIT: now usingtype WrapStatic[T:static] = object
would make make genericParams support static[T] generic params #13433 cleaner (although I argue this PR can be merged before we implement support fortype WrapStatic[T:static] = object
and then we'll change it totype WrapStatic[T:static] = object
once support is added);type WrapStatic[T:static type] = object
The text was updated successfully, but these errors were encountered: