30 lines
608 B
Mojo
30 lines
608 B
Mojo
# probe: an early return: is the value destroyed before the return on that path?
|
|
struct L(Copyable, Movable):
|
|
var n: String
|
|
|
|
def __init__(out self, n: String):
|
|
self.n = n
|
|
print("init", 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 run(flag: Bool) -> Int:
|
|
var a = L("a")
|
|
if flag:
|
|
print("returning early")
|
|
return 1
|
|
print("late uses", a.n)
|
|
return 2
|
|
|
|
|
|
def main():
|
|
print(run(True))
|
|
print("---")
|
|
print(run(False))
|