Skip to content

Commit

Permalink
fix nested call regression in generic bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jun 29, 2023
1 parent c6c85f8 commit 886477a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,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
Expand Down Expand Up @@ -2213,6 +2220,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
Expand Down
20 changes: 20 additions & 0 deletions tests/statictypes/tgenericcomputedrange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 886477a

Please sign in to comment.