diff options
-rw-r--r-- | compiler/sigmatch.nim | 13 | ||||
-rw-r--r-- | tests/generics/tuninstantiatedgenericcalls.nim | 18 |
2 files changed, 27 insertions, 4 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 18170ecfc..7a12b957b 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1196,10 +1196,15 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, return isGeneric of tyFromExpr: if c.c.inGenericContext > 0: - # generic type bodies can sometimes compile call expressions - # prevent expressions with unresolved types from - # being passed as parameters - return isNone + if not c.isNoCall: + # generic type bodies can sometimes compile call expressions + # prevent expressions with unresolved types from + # being passed as parameters + return isNone + else: + # Foo[templateCall(T)] shouldn't fail early if Foo has a constraint + # and we can't evaluate `templateCall(T)` yet + return isGeneric else: discard case f.kind diff --git a/tests/generics/tuninstantiatedgenericcalls.nim b/tests/generics/tuninstantiatedgenericcalls.nim index 63ba3908f..2163789e7 100644 --- a/tests/generics/tuninstantiatedgenericcalls.nim +++ b/tests/generics/tuninstantiatedgenericcalls.nim @@ -145,3 +145,21 @@ block: # issue #23730 proc test(M: static[int]): array[1 shl M, int] = discard doAssert len(test(3)) == 8 doAssert len(test(5)) == 32 + +block: # issue #19819 + type + Example[N: static int] = distinct int + What[E: Example] = Example[E.N + E.N] + +block: # issue #23339 + type + A = object + B = object + template aToB(t: typedesc[A]): typedesc = B + type + Inner[I] = object + innerField: I + Outer[O] = object + outerField: Inner[O.aToB] + var x: Outer[A] + doAssert typeof(x.outerField.innerField) is B |