Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
using generics in param initializers gives undeclared identifier
Example
# Error: undeclared identifier: 'T'
proc fun1[T](a: T, b = default(T)) = discard
fun1(1, 2)
# ditto
proc foo2(T: typedesc): auto = 0
proc fun2[T](a: T, b = foo2(T)) = discard
fun2(1, 2)
# ditto
proc foo3[T](): auto = 0
proc fun3[T](a: T, b = foo3[T]()) = discard
fun3(1, 2)
# this one works
type Foo4[T] = T
proc fun4[T](a: T, b: Foo4[T]) = discard
fun4(1, 2)
Current Output
Error: undeclared identifier: 'T'
Expected Output
should work
Additional Information
Your Nim version (output of nim -v).
latest devel c0d240b8cd3dc08d25c671b0dc7614fbfa980c2e
A link to a related issue or discussion.
this is definitely related to https://github.com/nim-lang/Nim/issues/8551 but I'm hesitant to call it a duplicate: this one is for parameter initializers, the other one was for proc return type. Also, the examples given here are much simpler and should just work.
No longer undeclared identifier: T but the compiler doesn't even attempt to infer a proper type for b so it never matches, works in every case by specifying b: T
using generics in param initializers gives
undeclared identifier
Example
Current Output
Error: undeclared identifier: 'T'
Expected Output
should work
Additional Information
nim -v
). latest devel c0d240b8cd3dc08d25c671b0dc7614fbfa980c2e