-
-
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
Cannot extract generic parameter from normal parameter in proc heading #8459
Comments
This is probably a bug, but just in case you don't know, the simplest and more readable way to write this would be proc doThing[T](foo: Foo[T]): Bar[T] =
result.b = foo.a |
Iirc, this only works for static, and is completely undocumented. I'm also not super fan of this because the "T" or "N" seems to come from nowhere: Static compiles type
Foo[N: static[int]] = object
a: array[N, int]
Bar[N: static[int]] = object
b: array[N, float]
proc doThing(foo: Foo): Bar[Foo.N] =
for i, v in foo.a:
result.b[i] = v.float
var foo: Foo[2]
foo.a = [100, 200]
let what = doThing(foo) cc @zah |
It is documented (a few paragraphs down) and it should work even for non-static: https://nim-lang.org/docs/manual.html#generics-type-classes This works: type
Foo[T] = object
a: T
proc doThing(foo: Foo): Foo.T =
result = foo.a
var foo: Foo[int]
foo.a = 100
let what = doThing(foo) But this doesn't: type
Foo[T] = object
a: T
Bar[T] = object
b: T
proc doThing(foo: Foo): Bar[Foo.T] =
result.b = foo.a
var foo: Foo[int]
foo.a = 100
let what = doThing(foo) |
Duplicate of #8433 |
@awr1 should we close as duplicate? |
will close then as a duplicate of #8433 |
I don't consider this a duplicate of #8433, due to the particulars of the compiler internal structures ( |
indeed this wasn't a duplicate of #8433 : just sent a PR #8554 that provides a better workaround for #8433, but doesn't address this issue. This isssue could in fact be related to #8551 ; it looks like root cause is that type inference is incomplete for return type; I feel like the issue here with |
output:
The text was updated successfully, but these errors were encountered: