Skip to content

Commit

Permalink
ignore uninstantiated static on match to base type
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jun 18, 2024
1 parent 09b5ed2 commit 09584c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TypeMapping): PS
elif t.kind in {tyGenericParam, tyConcept}:
localError(c.config, a.info, errCannotInstantiateX % q.name.s)
t = errorType(c)
elif isUnresolvedStatic(t) and c.inGenericContext == 0 and
c.matchedConcept == nil:
elif isUnresolvedStatic(t) and (q.typ.kind == tyStatic or
(q.typ.kind == tyGenericParam and
q.typ.genericParamHasConstraints and
q.typ.genericConstraint.kind == tyStatic)) and
c.inGenericContext == 0 and c.matchedConcept == nil:
# generic/concept type bodies will try to instantiate static values but
# won't actually use them
localError(c.config, a.info, errCannotInstantiateX % q.name.s)
Expand Down
5 changes: 5 additions & 0 deletions tests/generics/tuninstantiatedgenericcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ block: # issue #1771

var a: Foo[range[0..2], float]
doAssert test(a) == 0.0

block: # issue #23730
proc test(M: static[int]): array[1 shl M, int] = discard
doAssert len(test(3)) == 8
doAssert len(test(5)) == 32

0 comments on commit 09584c5

Please sign in to comment.