Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Implicit generic fails to instantaite default proc before parameters supplied

Open Graveflo opened this issue 8 months ago • 2 comments

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-04-22
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: d966ee3fc3874f63b4e32a7edc7566982bb570ce
active boot switches: -d:release

Description

kind of hard to title this one but the example is clear:

proc p*[T](a: T) = discard
type
  A*[B] = object
    x = p[A[B]]
proc s(x: A) = discard

Current Output

Error: unhandled exception: semcall.nim(366, 11) `n[0].kind == nkBracketExpr and pos < n[0].len`  [AssertionDefect]

Expected Output


Known Workarounds

Although this won't work well for my use case it's worth noting that:

proc s[T](x: A[T]) = discard

works

Additional Information

No response

Graveflo avatar Apr 23 '25 00:04 Graveflo

Internal errors are bad but you cannot initialize the field x with a var T proc that returns nothing...

Araq avatar Apr 23 '25 03:04 Araq

Internal errors are bad but you cannot initialize the field x with a var T proc that returns nothing...

I removed the var in an edit FYI since it didn't matter. I'm not sure what you mean though. I'm trying to explicitly instantiate p for a function pointer. Like this, except x doesn't start off as nil:

type
  A*[B] = object
    x: proc (a: A[B])

Graveflo avatar Apr 23 '25 04:04 Graveflo