Open AZMCode opened 1 year ago
I haven't checked as of yet, but similar bugs could be hidden in the other control functions.
this is indeed a bug when b
is a linear type -- thanks for catching this! Your suggested fix (1.) looks good to me, if you want, you can open a PR with it and the team can review it and if it's good to go we can merge.
Got it. I'll test it a little bit before submitting the PR
The current definition of
Control.iterate-until
is as such:This definition hands the ownership of the
result
variable to thepred
function, then reuses it forf
, meaning that the variableresult
is undefined by the time an attempt to transform it is made.The compiler gladly warns us about this, but only when used:
As per fixing this there are two options, to my understanding:
Handing a reference to
pred
. This avoids requiring theresult
be able to be copied, but at the expense of changing the function signature. I have made this alteration locally to core, and can confirm it works as expected.Copying the
result
internally. This avoids changing the function signature, at the expense of requiring theresult
be copyable, and doing so every iteration.Given the goals of the language I'd strongly suggest The first option, but that's up to you people.