Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 authored and bung committed May 25, 2023
1 parent b18fef7 commit e40c35f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
else: result = newSymNode(s, n.info)
of tyStatic:
let staticDuringGenericInst = (c.inStaticContext > 0 and c.inGenericInst > 0)
if (c.inExplicitGenericSym <= 0 or staticDuringGenericInst) and typ.n != nil:
if (c.inExplicitGenericSym <= 0 or staticDuringGenericInst or efInTypeof in flags) and typ.n != nil:
result = typ.n
result.typ = typ.base
else:
Expand Down
7 changes: 5 additions & 2 deletions tests/generics/t10833.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
type Foo*[A; B; C: static[int]] = object
s: string
# d: typeof(C)
f: typeof(C)

proc build*[A; B; C: static[int]](s: string;): Foo[A, B, C] =
const d = C
doAssert d == 1
result.s = s
result.f = C

proc build*[A; B; C: static[int]](): Foo[A, B, C] =
build[A, B, C]("foo")
Expand All @@ -13,4 +15,5 @@ type
Bar = object
Baz = object
let r = build[Bar, Baz, 1]()
doAssert r.s == "foo"
doAssert r.s == "foo"
doAssert r.f == 1
27 changes: 27 additions & 0 deletions tests/generics/t10833_2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type MyObject = object
x, y: int
s: string

const c = MyObject(x: 1, y: 2, s: "")

type Foo[A, B; C: static MyObject] = object
s: string
f: typeof(C)

proc build*[A; B; C: static MyObject](s: string;): Foo[A, B, C] =
const d = C
doAssert d.x == c.x
doAssert d.x == 1
result.f = d
result.s = s

proc build*[A; B; C: static MyObject](): Foo[A, B, C] =
build[A, B, C]("foo")

type
Bar = object
Baz = object

let r = build[Bar, Baz, c]()
doAssert r.s == "foo"
doAssert r.f == c
27 changes: 27 additions & 0 deletions tests/generics/t10833_3.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type MyObject = object
x, y: int
s: string

const c = @[MyObject(x: 1, y: 2, s: "")]

type Foo[A, B; C: static seq[MyObject]] = object
s: string
f: typeof(C)

proc build*[A; B; C: static seq[MyObject]](s: string;): Foo[A, B, C] =
const d = C
doAssert d[0].x == c[0].x
doAssert d[0].x == 1
result.f = d
result.s = s

proc build*[A; B; C: static seq[MyObject]](): Foo[A, B, C] =
build[A, B, C]("foo")

type
Bar = object
Baz = object

let r = build[Bar, Baz, c]()
doAssert r.s == "foo"
doAssert r.f == c

0 comments on commit e40c35f

Please sign in to comment.