28 lines
621 B
Mojo
28 lines
621 B
Mojo
# probe: mut arguments changing a caller's list and struct
|
|
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
|
# expect-stdout: 7
|
|
# expect-stdout: [0, 10, 20, 30, 0, 10] 6
|
|
@fieldwise_init
|
|
struct Counter(Copyable, Movable):
|
|
var hits: Int
|
|
|
|
|
|
def bump(mut c: Counter, by: Int):
|
|
c.hits += by
|
|
|
|
|
|
def fill(mut xs: List[Int], n: Int):
|
|
for i in range(n):
|
|
xs.append(i * 10)
|
|
|
|
|
|
def main():
|
|
var c = Counter(0)
|
|
bump(c, 3)
|
|
bump(c, 4)
|
|
print(c.hits)
|
|
var xs = List[Int]()
|
|
fill(xs, 4)
|
|
fill(xs, 2)
|
|
print(xs, len(xs))
|