-
-
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
Regression from 2.0.8/version-2-0
to version-2-2
/devel
with Error: type mismatch
with templates and generics
#24125
Comments
Partial explicit generic instantations are not in the language spec. |
Ok |
template v[T](c: SomeOrdinal): T = T(c)
discard v[int, char]('A') outputs
|
This happens in error reporting as a mistake from
Also the second generic parameter isn't needed in this case. |
The compiler shouldn't crash though, regardless |
refs #24010, refs #24125 (comment) The generic mismatch errors added in #24010 made it possible for `nArg` to be `nil` in the error reporting since it checked the call argument list, not the generic parameter list for the mismatching argument node, which causes a segfault. This is fixed by checking the generic parameter list immediately on any generic mismatch error. Also the `typedesc` type is skipped for the value of the generic params since it's redundant and the generic parameter constraints don't have it.
This works fine template v[T](c: SomeOrdinal): T = T(c)
discard v[int](1) but template v[T](c: SomeOrdinal): T = T(c)
discard v[int, char](1) causes
I think it should be sth like "invalid type parameter char". This error logic could be causing more hidden bugs. What do you think? |
The extra generic parameter is allowed there because template v[T; #[hidden]# cType: SomeOrdinal](c: cType): T = T(c) Some libraries depended on being able to assign to this hidden generic parameter so it was kept allowed, which is why the compiler gives the error "expected SomeOrdinal", because it's trying to overwrite it. Maybe this could be mentioned in the error message, that an implicit generic parameter is being assigned. The reason we can't support only partially giving the generic parameters is because it makes overloading ambiguous with differing generic parameter numbers and can cause instantiation issues for parameters that aren't properly constrained (i.e. |
Thanks a lot for explaining. What do you think about the following? template v[T](c: SomeOrdinal): T =
echo "v1"
T(c)
discard v[int, int](1) prints v1 template v[T](c: SomeOrdinal): T =
echo "v1"
T(c)
template v[T, U](c: SomeOrdinal): T =
echo "v2"
T(c)
discard v[int, int](1) prints v2
The same happens with 2.0.8 and 1.6.20. |
It's not good, if you change the order of the templates it prints |
…#24140) refs nim-lang#24010, refs nim-lang#24125 (comment) The generic mismatch errors added in nim-lang#24010 made it possible for `nArg` to be `nil` in the error reporting since it checked the call argument list, not the generic parameter list for the mismatching argument node, which causes a segfault. This is fixed by checking the generic parameter list immediately on any generic mismatch error. Also the `typedesc` type is skipped for the value of the generic params since it's redundant and the generic parameter constraints don't have it.
Description
Nim Version
Builds:
Doesn't build:
Current Output
Expected Output
No response
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: