Skip to content

Commit

Permalink
cleaner refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Nov 10, 2024
1 parent 5abb54a commit 972b130
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
16 changes: 1 addition & 15 deletions compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,6 @@ proc lookupTypeVar(cl: var TReplTypeVars, t: PType): PType =
result = cl.typeMap.lookup(t)
if result == nil:
if cl.allowMetaTypes or tfRetType in t.flags: return

if t.kind == tyStatic:
return nil

localError(cl.c.config, t.sym.info, "cannot instantiate: '" & typeToString(t) & "'")
result = errorType(cl.c)
# In order to prevent endless recursions, we must remember
Expand Down Expand Up @@ -429,22 +425,12 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
return
for i in FirstGenericParamAt..<t.kidsLen:
var x = t[i]
if x.kind in {tyGenericParam}:
if x.kind == tyGenericParam or (x.kind == tyStatic and x.n == nil):
x = lookupTypeVar(cl, x)
if x != nil:
if header == t: header = instCopyType(cl, t)
header[i] = x
propagateToOwner(header, x)
elif x.kind in {tyStatic}:
let y = lookupTypeVar(cl, x)
# In templates the lookup can lead to concrete types like tyInt instead of tyStatic,
# which can't be handled like this.
if y != nil and y.kind == tyStatic:
if header == t: header = instCopyType(cl, t)
header[i] = y
propagateToOwner(header, y)
else:
propagateToOwner(header, x)
else:
propagateToOwner(header, x)

Expand Down
14 changes: 0 additions & 14 deletions tests/generics/t23628.nim

This file was deleted.

19 changes: 19 additions & 0 deletions tests/generics/tstaticinstcache.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
block: # issue #23628, simple case
type
Bar[T] = object

Foo[T; C: static int] = object
bar: Bar[Foo[T, C]]

var f: Foo[int, 5]

block: # issue #23628, nested
type
Bar[T; C: static int] = object
arr: array[C, ptr T]

Foo[T; C: static int] = object
bar: Bar[Foo[T, C], C]

var f: Foo[int, 5]
doAssert f.bar.arr.len == 5

0 comments on commit 972b130

Please sign in to comment.