Repository navigation
Closed
Description
Summary
match over a Copy enum field can make the compiler treat the whole owner as moved when one arm consumes the owner but returns from the function. This blocks normal state-machine code where the consuming arm exits and the fallthrough path returns the original state.
match state.mode:
.Hidden => intents.push(Intent.SetAnimation("hidden"))
_ =>
let (next, more) = start_going_hero(state)
for intent in more:
intents.push(intent)
return (next, intents)
(state, intents)
The owner should remain available after the match because the only arm that moves it exits the function.
Version
with v0.15.1-g1f9ec5626
Repro 1
with run resources/enemies/slime_cyan.wRelevant source:
pub fn on_restarted(state: SlimeCyanState) -> (SlimeCyanState, Vec[Intent]):
var intents: Vec[Intent] = Vec.new()
intents.push(Intent.RemoveNamedSprite("shadow"))
match state.mode:
.Hidden => intents.push(Intent.SetAnimation("hidden"))
_ =>
let (next, more) = start_going_hero(state)
for intent in more:
intents.push(intent)
intents.push(Intent.ScheduleGroundCheck(300))
intents.push(Intent.ScheduleHeroCheck(30))
return (next, intents)
intents.push(Intent.ScheduleGroundCheck(300))
intents.push(Intent.ScheduleHeroCheck(30))
(state, intents)
Actual:
error: use of moved value
--> resources/enemies/slime_cyan.w:139:6
139 | (state, intents)
| ^^^^^
error: run failed
Repro 2
From the same repo, run:
with run resources/enemies/slime_green.wRelevant source:
pub fn on_hero_check(state: SlimeState, obs: Observation) -> (SlimeState, Vec[Intent]):
if obs.hero_distance <= DETECTION_DISTANCE:
match state.mode:
.Hidden => return unhide(state)
_ => ()
else:
match state.mode:
.GoingHero => return hide(state)
_ => ()
var intents: Vec[Intent] = Vec.new()
intents.push(Intent.ScheduleHeroCheck(30))
(state, intents)
Actual:
error: use of moved value
--> resources/enemies/slime_green.w:154:15
154 | match state.mode:
| ^^^^^
error: use of moved value
--> resources/enemies/slime_green.w:155:39
155 | .GoingHero => return hide(state)
| ^^^^^
error: use of moved value
--> resources/enemies/slime_green.w:159:6
159 | (state, intents)
| ^^^^^
error: run failed
The same file also reproduces the post-match return failure in on_restarted.
Expected
- Matching a
Copyenum field such asstate.modeshould not movestate. - If one
matcharm movesstateand returns from the function, later code should only need to be valid for the non-returning arms. - Multiple conditional matches over the same
Copyfield should not poison the owner for later use.
Notes
This came up while porting Smallhold resources. I avoided rewriting the state-machine match blocks to if so the compiler issue remains visible.
Metadata
Metadata
Assignees
Labels
No labels
Activity
ehartford commentedon Jun 27, 2026
Fixed by the match-arm move-state union-join (this commit). check_match_expr now snapshots the entry move-state, analyzes each arm from it, and unions only the non-diverging arm exits — so an arm that consumes the owner and returns no longer marks the owner moved on the fallthrough. Verified: test/behavior/behav_match_returning_arm_move.w compiles and runs; full fresh :test green.
docs: branch-merge soundness root-cause + fix recommendation (#612, #579
Sema: union-join move-state across match arms (#612, #579)
docs(resume_later): branch-merge fixed; Slice D (loops) is the active…
docs: align drop/move ownership docs with the niche; archive complete…