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.25k stars 1.46k forks source link

`type` doesn't work with generics (and `default`) in a function definition #11112

Open dawkot opened 5 years ago

dawkot commented 5 years ago
proc foo[A, B]: type(A.default + B.default) =
  discard

system.+: proc (x: float32, y: float32): float32{.noSideEffect.} ambiguous call; both system.+(x: float32, y: float32) [declared in C:\Users\dawkot.choosenim\toolchains\nim-#devel\lib\system.nim(1507, 6)] and system.+(x: int32, y: int32) [declared in C:\Users\dawkot.choosenim\toolchains\nim-#devel\lib\system.nim(1209, 6)] match for: (type(A.default), type(B.default))

Of course, something similiar works without generics:

proc foo[A, B]: type(int8.default + int16.default) =
  discard
metagn commented 10 months ago

Related #15959 and more I can't find (early generics), default is evaluated eagerly on the unresolved generic types A and B