nim-lang / Nim

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).
https://nim-lang.org
Other
16.46k stars 1.47k forks source link

using generics in param initializers gives `undeclared identifier` #11915

Open timotheecour opened 5 years ago

timotheecour commented 5 years ago

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

metagn commented 1 month ago

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