Skip to content

Commit

Permalink
fix #6637 array index type depends generic (#20673)
Browse files Browse the repository at this point in the history
(cherry picked from commit aa6f9d4)
  • Loading branch information
bung87 authored and narimiran committed Apr 25, 2023
1 parent 8597c60 commit bf4c882
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ proc semArrayIndex(c: PContext, n: PNode): PType =
elif e.kind == nkSym and e.typ.kind == tyStatic:
if e.sym.ast != nil:
return semArrayIndex(c, e.sym.ast)
if not isOrdinalType(e.typ.lastSon):
if e.typ.lastSon.kind != tyGenericParam and not isOrdinalType(e.typ.lastSon):
let info = if n.safeLen > 1: n[1].info else: n.info
localError(c.config, info, errOrdinalTypeExpected)
result = makeRangeWithStaticExpr(c, e)
Expand Down
9 changes: 9 additions & 0 deletions tests/generics/t6637.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

type
Grid2D*[I: SomeInteger, w, h: static[I], T] = object
grid: array[w, array[h, T]]
Grid2DIns = Grid2D[int, 2, 3, uint8]

let a = Grid2DIns()
doAssert a.grid.len == 2
doAssert a.grid[0].len == 3

0 comments on commit bf4c882

Please sign in to comment.