Nim icon indicating copy to clipboard operation
Nim copied to clipboard

using generics in param initializers gives `undeclared identifier`

Open timotheecour opened this issue 6 years ago • 1 comments
trafficstars

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.

timotheecour avatar Aug 08 '19 10:08 timotheecour