diff options
Diffstat (limited to 'tests/destructor')
-rw-r--r-- | tests/destructor/t12037.nim | 18 | ||||
-rw-r--r-- | tests/destructor/tdestructor_too_late.nim | 14 | ||||
-rw-r--r-- | tests/destructor/tmove_objconstr.nim | 17 | ||||
-rw-r--r-- | tests/destructor/tnewruntime_misc.nim | 8 | ||||
-rw-r--r-- | tests/destructor/tv2_cast.nim | 3 |
5 files changed, 57 insertions, 3 deletions
diff --git a/tests/destructor/t12037.nim b/tests/destructor/t12037.nim new file mode 100644 index 000000000..8d50262d6 --- /dev/null +++ b/tests/destructor/t12037.nim @@ -0,0 +1,18 @@ +discard """ + cmd: '''nim c --newruntime $file''' + output: ''' +showing original type, length, and contents seq[int] 1 @[42] +copy length and contents 1 @[42] +''' +""" + +proc test() = + var sq1 = @[42] + echo "showing original type, length, and contents ", sq1.typeof, " ", sq1.len, " ", sq1 + doAssert cast[int](sq1[0].unsafeAddr) != 0 + var sq2 = sq1 # copy of original + echo "copy length and contents ", sq2.len, " ", sq2 + doAssert cast[int](sq2[0].unsafeAddr) != 0 + doAssert cast[int](sq1[0].unsafeAddr) != 0 + +test() diff --git a/tests/destructor/tdestructor_too_late.nim b/tests/destructor/tdestructor_too_late.nim new file mode 100644 index 000000000..d279280ba --- /dev/null +++ b/tests/destructor/tdestructor_too_late.nim @@ -0,0 +1,14 @@ +discard """ + errmsg: "cannot bind another '=destroy' to: Obj; previous declaration was constructed here implicitly: tdestructor_too_late.nim(7, 16)" +""" +type Obj* = object + v*: int + +proc something(this: sink Obj) = + discard + +proc `=destroy`(this: var Obj) = + echo "igotdestroyed" + this.v = -1 + +var test* = Obj(v: 42) \ No newline at end of file diff --git a/tests/destructor/tmove_objconstr.nim b/tests/destructor/tmove_objconstr.nim index bfc819ceb..be92d1503 100644 --- a/tests/destructor/tmove_objconstr.nim +++ b/tests/destructor/tmove_objconstr.nim @@ -175,4 +175,19 @@ proc myfuncLoop(x: int): MySeqNonCopyable = var cc = newMySeq(i, 5.0) result = cc -discard myfuncLoop(3) \ No newline at end of file +discard myfuncLoop(3) + +#------------------------------------------------------------ +# Move into table via openarray +#------------------------------------------------------------ + +type + TableNonCopyable = object + x: seq[(string, MySeqNonCopyable)] + +proc toTable(pairs: sink openArray[(string, MySeqNonCopyable)]): TableNonCopyable = + discard + + +let mytable = {"a": newMySeq(2, 5.0)}.toTable + diff --git a/tests/destructor/tnewruntime_misc.nim b/tests/destructor/tnewruntime_misc.nim index c5f978a98..d6c03b9b0 100644 --- a/tests/destructor/tnewruntime_misc.nim +++ b/tests/destructor/tnewruntime_misc.nim @@ -75,5 +75,13 @@ proc selfAssign = selfAssign() +# bug #11833 +type FooAt = object + +proc testWrongAt() = + var x = @[@[FooAt()]] + +testWrongAt() + let (a, d) = allocCounters() discard cprintf("%ld new: %ld\n", a - unpairedEnvAllocs() - d, allocs) diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim index 8a4d69ef0..9c05b2ae1 100644 --- a/tests/destructor/tv2_cast.nim +++ b/tests/destructor/tv2_cast.nim @@ -2,7 +2,6 @@ discard """ cmd: '''nim c --newruntime $file''' output: '''@[1] @[116, 101, 115, 116] -test @[1953719668, 875770417]''' """ @@ -13,7 +12,7 @@ echo cast[seq[uint8]](@[1]) echo cast[seq[uint8]]("test") discard cast[string](@[116'u8, 101, 115, 116]) -echo cast[string](@[116'u8, 101, 115, 116]) +#echo cast[string](@[116'u8, 101, 115, 116, 0]) var a = cast[seq[uint32]]("test1234") a.setLen(2) echo a |