Skip to content

Commit

Permalink
Fix segfault caused by ensuring valueless statics are not evaluated (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 authored Mar 29, 2023
1 parent 2315b01 commit c06623b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ proc hasValuelessStatics(n: PNode): bool =
proc doThing(_: MyThing)
]#
if n.safeLen == 0:
n.typ.kind == tyStatic
n.typ == nil or n.typ.kind == tyStatic
else:
for x in n:
if hasValuelessStatics(x):
Expand Down
20 changes: 20 additions & 0 deletions tests/statictypes/tstatictypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,23 @@ var sorted = newSeq[int](1000)
for i in 0..<sorted.len: sorted[i] = i*2
doAssert isSorted2(sorted, compare)
doAssert isSorted2(sorted, proc (a, b: int): bool {.inline.} = a < b)


block: # Ensure static descriminated objects compile
type
ObjKind = enum
KindA, KindB, KindC

MyObject[kind: static[ObjKind]] = object of RootObj
myNumber: int
when kind != KindA:
driverType: int
otherField: int
elif kind == KindC:
driverType: uint
otherField: int

var instance: MyObject[KindA]
discard instance
discard MyObject[KindC]()

0 comments on commit c06623b

Please sign in to comment.