-
-
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: type mismatch: got <typedesc[A]>, but expected one of: A = proc (){.closure.} #23587
Comments
Also spotted: https://forum.nim-lang.org/t/12547 @haoyu234 Have you found any workaround to this? |
Took me a second to figure it out, the issue is this call: Nim/lib/pure/collections/tables.nim Line 437 in f73e03b
It tries to call the parameter proc foo(default: proc ()) =
echo default(int)
foo(123) which seems to fail in all versions, Very easily worked around by just removing this call from |
fixes #23587 As explained in the issue, `getOrDefault` has a parameter named `default` that can be a proc after generic instantiation. But the parameter having a proc type [overrides all other overloads](https://github.com/nim-lang/Nim/blob/f73e03b1323cf3ed65d6996f43c8e6891c40f924/compiler/semexprs.nim#L1203) including the magic `system.default` overload and causes a compile error if the proc doesn't match the normal use of `default`. To fix this, the `result = default(B)` initializer call is removed because it's not needed, `result` is always set in `getOrDefaultImpl` when a default value is provided. This is still a suspicious behavior of the compiler but `tables` working has a higher priority.
This workaround seems ok, but for non- import std/tables
var t: Table[int, int]
echo t.getOrDefault(0, default=2) A preliminary search of Nimble packages makes that seems very rare. As a (probably already known) simple meta-rule, if you must change call sites in / uses by the compiler, you should likely put in a changelog. Some dark/non-nimble-published code might like the self-documenting/more explicit kw param calls => changelog, even if the compile error in that case might be clear. |
fixes #23587 As explained in the issue, `getOrDefault` has a parameter named `default` that can be a proc after generic instantiation. But the parameter having a proc type [overrides all other overloads](https://github.com/nim-lang/Nim/blob/f73e03b1323cf3ed65d6996f43c8e6891c40f924/compiler/semexprs.nim#L1203) including the magic `system.default` overload and causes a compile error if the proc doesn't match the normal use of `default`. To fix this, the `result = default(B)` initializer call is removed because it's not needed, `result` is always set in `getOrDefaultImpl` when a default value is provided. This is still a suspicious behavior of the compiler but `tables` working has a higher priority. (cherry picked from commit 67ea754)
refs #23587 (comment) (cherry picked from commit bb00065)
Description
https://play.nim-lang.org/#pasty=cVWRkhXTOfpv
Compiles normally on 'play.nim-lang.org' without uncommenting.
Compiling locally will report an error, just like the title says.
Nim Version
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-05-05
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 1ef4d04
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: