tokiwa-software / fuzion

The Fuzion Language Implementation
https://fuzion-lang.dev
GNU General Public License v3.0
48 stars 11 forks source link

`mutate` instance can be re-entered, permitting mutation without visible effect #4218

Open fridis opened 6 days ago

fridis commented 6 days ago

In this example, feature f does not have any visible effects apart from io.out, but it performs a state change to v

m : mutate is
m1 := m

v := m1.instate_self ()->
  say "start"
  r := m.env.new 42
  say "r = $r"
  r

# f uses no effects, but mutates `v`
f ! io.out =>
  _ := m1.instate_self ()->
    v <- 4711 + v
    say "updated v via m1: $v"

f; f; f

which can be seen when running the code that produces different output

 > ./build/bin/fz repeated_mutate1.fz 
start
r = 42
updated v via m1: 4753
updated v via m1: 9464
updated v via m1: 14175