Files
pplus-core/mojo/probes/life-last-use.mojo
T
2026-10-05 03:03:38 +00:00

27 lines
674 B
Mojo

# probe: is a variable destroyed at its last use, before later statements run?
struct Loud(Copyable, Movable):
var name: String
def __init__(out self, name: String):
self.name = name
print("init", name)
def __init__(out self, *, copy: Self):
self.name = copy.name + "'"
print("copy", copy.name)
def __init__(out self, *, deinit move: Self):
self.name = move.name^
print("move", self.name)
def __deinit__(deinit self):
print("destroy", self.name)
def main():
var a = Loud("a")
print("a made")
var b = Loud("b")
print("b made, a used last at:", a.name)
print("end of main")