Files
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

33 lines
795 B
Mojo

# probe: in what order are a struct's fields destroyed?
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)
struct Pair(Movable):
var first: Loud
var second: Loud
def __init__(out self, var first: Loud, var second: Loud):
self.first = first^
self.second = second^
def main():
var p = Pair(Loud("x"), Loud("y"))
print("made pair", p.first.name, p.second.name)