Files
pplus-web/mojo/probes/life-move-into-var-arg.mojo
T
2026-10-05 03:03:38 +00:00

38 lines
841 B
Mojo

# probe: Stage 4 prediction: x^ into a var argument runs no constructor; into a new variable the move constructor runs
# expect-stdout: init a
# expect-stdout: copy a
# expect-stdout: took a2
# expect-stdout: bye a2
# expect-stdout: move a
# expect-stdout: kept a
# expect-stdout: bye a
struct L(Copyable, Movable):
var n: String
def __init__(out self, n: String):
self.n = n
print("init", n)
def __init__(out self, *, copy: Self):
self.n = copy.n + "2"
print("copy", copy.n)
def __init__(out self, *, deinit move: Self):
self.n = move.n^
print("move", self.n)
def __deinit__(deinit self):
print("bye", self.n)
def take(var t: L):
print("took", t.n)
def main():
var a = L("a")
var c = a.copy()
take(c^)
var d = a^
print("kept", d.n)