123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- discard """
- target: "c js"
- matrix: "--cursorinference:on; --cursorinference:off"
- """
- block:
- type
- X = object
- s: string
- proc `=copy`(x: var X, y: X) =
- x.s = "copied " & y.s
- proc `=sink`(x: var X, y: X) =
- `=destroy`(x)
- wasMoved(x)
- x.s = "moved " & y.s
- proc consume(x: sink X) =
- discard x.s
- proc main =
- let m = "abcdefg"
- var x = X(s: ensureMove m)
- consume(ensureMove x)
- static: main()
- main()
- block:
- type
- String = object
- id: string
- proc hello =
- var s = String(id: "1")
- var m = ensureMove s
- doAssert m.id == "1"
- hello()
- block:
- type
- String = object
- id: string
- proc hello =
- var n = "1"
- var s = String(id: ensureMove n)
- var m = ensureMove s
- doAssert m.id == "1"
- hello()
- block:
- type
- String = object
- id: string
- proc hello =
- var n = "1"
- var s = [ensureMove n]
- var m = ensureMove s
- doAssert m[0] == "1"
- hello()
- block:
- type
- String = object
- id: string
- proc hello =
- var n = "1"
- var s = @[ensureMove n]
- var m = ensureMove s
- doAssert m[0] == "1"
- hello()
- block:
- type
- String = object
- id: string
- proc hello =
- var s = String(id: "1")
- var m = ensureMove s.id
- doAssert m == "1"
- hello()
- block:
- proc foo =
- var x = 1
- let y = ensureMove x # move
- when not defined(js):
- doAssert (y, x) == (1, 0) # (1, 0)
- foo()
- block:
- proc foo =
- var x = 1
- let y = ensureMove x # move
- doAssert y == 1
- foo()
- block:
- proc foo =
- var x = @[1, 2, 3]
- let y = ensureMove x[0] # move
- doAssert y == 1
- when not defined(js):
- doAssert x == @[0, 2, 3]
- foo()
- block:
- proc foo =
- var x = [1, 2, 3]
- let y = ensureMove x[0] # move
- doAssert y == 1
- when not defined(js):
- doAssert x == @[0, 2, 3]
- foo()
- block:
- proc foo =
- var x = @["1", "2", "3"]
- let y = ensureMove x[0] # move
- doAssert y == "1"
- foo()
|