From be4bd8a0edd527b24679372b8cb9d2afa548056d Mon Sep 17 00:00:00 2001 From: Aditya Siram Date: Thu, 22 Sep 2022 13:19:36 -0500 Subject: Fixes #20348; only respect the recursion limit if the symbol's generic type has been generated by the compiler (#20377) Fixes #20348 --- compiler/semtypinst.nim | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'compiler/semtypinst.nim') diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 504b83b4c..945667a81 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -499,17 +499,20 @@ proc propagateFieldFlags(t: PType, n: PNode) = proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = template bailout = - if cl.recursionLimit > 100: - # bail out, see bug #2509. But note this caching is in general wrong, - # look at this example where TwoVectors should not share the generic - # instantiations (bug #3112): - - # type - # Vector[N: static[int]] = array[N, float64] - # TwoVectors[Na, Nb: static[int]] = (Vector[Na], Vector[Nb]) - result = PType(idTableGet(cl.localCache, t)) - if result != nil: return result - inc cl.recursionLimit + if t.sym != nil and sfGeneratedType in t.sym.flags: + # Only consider the recursion limit if the symbol is a type with generic + # parameters that have not been explicitly supplied, typechecking should + # terminate when generic parameters are explicitly supplied. + if cl.recursionLimit > 100: + # bail out, see bug #2509. But note this caching is in general wrong, + # look at this example where TwoVectors should not share the generic + # instantiations (bug #3112): + # type + # Vector[N: static[int]] = array[N, float64] + # TwoVectors[Na, Nb: static[int]] = (Vector[Na], Vector[Nb]) + result = PType(idTableGet(cl.localCache, t)) + if result != nil: return result + inc cl.recursionLimit result = t if t == nil: return -- cgit 1.4.1-2-gfad0