mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
Fix segfault caused by ensuring valueless statics are not evaluated (#21577)
(cherry picked from commit c06623bf8c)
This commit is contained in:
@@ -201,7 +201,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):
|
||||
|
||||
@@ -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]()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user