fix nested call regression in generic bodies (#22189)

fixes #22187
This commit is contained in:
metagn
2023-06-29 23:05:18 +03:00
committed by GitHub
parent 41ec894cb0
commit 210b10dd0d
2 changed files with 31 additions and 0 deletions

View File

@@ -1140,6 +1140,13 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
let x = typeRel(c, a, f, flags + {trDontBind})
if x >= isGeneric:
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
else: discard
case f.kind
@@ -2215,6 +2222,10 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
of isNone:
# do not do this in ``typeRel`` as it then can't infer T in ``ref T``:
if a.kind in {tyProxy, tyUnknown}:
if a.kind == tyUnknown and c.inGenericContext > 0:
# don't bother with fauxMatch mechanism in generic type,
# reject match, typechecking will be delayed to instantiation
return nil
inc(m.genericMatches)
m.fauxMatch = a.kind
return arg

View File

@@ -95,3 +95,23 @@ block:
x[2] = 3
doAssert x == [0: 1, 1: 2, 2: 3]
doAssert x is array[0 .. 2, int]
block:
type Foo[T; U: static T] = array[T(0) .. (U * 2) + 1, int]
block:
var x: Foo[int, 1]
x[0] = 1
x[1] = 2
x[2] = 3
x[3] = 4
doAssert x == [0: 1, 1: 2, 2: 3, 3: 4]
doAssert x is array[0 .. 3, int]
block: # issue #22187
template m(T: type, s: int64): int64 = s
func p(n: int64): int = int(n)
type F[T; s: static int64] = object
k: array[p(m(T, s)), int64]
var x: F[int, 3]
doAssert x.k is array[3, int64]