diff options
-rw-r--r-- | compiler/liftdestructors.nim | 7 | ||||
-rw-r--r-- | tests/destructor/t12037.nim | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index a2d952e16..a906ac181 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -702,6 +702,12 @@ template inst(field, t) = proc isTrival(s: PSym): bool {.inline.} = s == nil or (s.ast != nil and s.ast[bodyPos].len == 0) + +proc isEmptyContainer(g: ModuleGraph, t: PType): bool = + (t.kind == tyArray and lengthOrd(g.config, t[0]) == 0) or + (t.kind == tySequence and t[0].kind == tyError) + + proc createTypeBoundOps(g: ModuleGraph; c: PContext; orig: PType; info: TLineInfo) = ## In the semantic pass this is called in strategic places ## to ensure we lift assignment, destructors and moves properly. @@ -710,6 +716,7 @@ proc createTypeBoundOps(g: ModuleGraph; c: PContext; orig: PType; info: TLineInf incl orig.flags, tfCheckedForDestructor let skipped = orig.skipTypes({tyGenericInst, tyAlias, tySink}) + if isEmptyContainer(skipped): return let h = sighashes.hashType(skipped, {CoType, CoConsiderOwned, CoDistinct}) var canon = g.canonTypes.getOrDefault(h) diff --git a/tests/destructor/t12037.nim b/tests/destructor/t12037.nim index 8d50262d6..57ebae9e4 100644 --- a/tests/destructor/t12037.nim +++ b/tests/destructor/t12037.nim @@ -16,3 +16,10 @@ proc test() = doAssert cast[int](sq1[0].unsafeAddr) != 0 test() + + +############################################# +### bug 12820 +import tables +var t = initTable[string, seq[ptr int]]() +discard t.hasKeyOrPut("f1", @[]) |