Home / Docs / Diagnostics
U2018: An edit argument together with another use of its binding in the same call
Release v0.4.0
A call that passes edit p may not use the root binding of p anywhere else: not in another argument, not as another edit or take argument, and not through a disjoint field, so f(edit r.x, y: r.y) is U2018 too (spec/17 §3 rule 4). The callee changes the place while the other argument is read, and exclusivity keeps the order of the two from mattering. Bind the other value with let before the call.
The repair at a glance
src/demo.una
module demo
pub kind Point
x: Int
y: Int
pub shift(edit p: Point, by: Int) -> Unit
=
p.x = p.x + by
pub step() -> Point
=
let edit p = Point(x: 1, y: 2)
- shift(edit p, by: p.y)
+ let dy = p.y
+ shift(edit p, by: dy)
pFailing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub kind Point
x: Int
y: Int
pub shift(edit p: Point, by: Int) -> Unit
=
p.x = p.x + by
pub step() -> Point
=
let edit p = Point(x: 1, y: 2)
shift(edit p, by: p.y)
pFixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub kind Point
x: Int
y: Int
pub shift(edit p: Point, by: Int) -> Unit
=
p.x = p.x + by
pub step() -> Point
=
let edit p = Point(x: 1, y: 2)
let dy = p.y
shift(edit p, by: dy)
p