You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Result[Unit, E] function ending in an assignment gets no implicit Ok(()): "return type mismatch" #1296
Found rewriting `examples/json-parser` under #1150 ruling 4 (`mut fn bump() -> Result[Unit, JsonError]: self.current = self.tokenizer.next_token()?`).
§10 / docs/with_for_ai.md §3: "For `Result[Unit, E]`, ending the function normally returns `Ok(())`." A function whose last statement is a call (`print(...)`) gets the implicit `Ok(())`; one whose last statement is an assignment or compound assignment does not:
```
error E = Bad
type P { cur: Option[i32] = None, n: i32 = 0 }
fn next(n: i32) -> Result[Option[i32], E]:
if n > 3: return Err(.Bad)
Some(n)
extend P:
mut fn bump() -> Result[Unit, E]:
self.cur = next(self.n)? // error: return type mismatch
mut fn bump2() -> Result[Unit, E]:
let c = next(self.n)?
self.cur = c // error: return type mismatch
mut fn bump3() -> Result[Unit, E]:
self.n += 1 // error: return type mismatch
```
Expected: all three compile and return `Ok(())`. Installed `with v0.15.2.1-g478b26481`. Likely the D43 tail inference treats an assignment tail as a value of the assigned type rather than as a statement ending the function.
The example spells an explicit `Ok(())` after the assignment until this lands.
Activity
examples: rewritten to the current spec (D55 ruling 4) + examples-tes…
Sema: assignment tails are discarded (#1296) and `with … as mut` bodi…
examples: restore the spec spellings #1308 parked behind now-fixed co…
Sema/MirLower: only a body's own tail discards an assignment; an arm …
Sema/MirLower: only a body's own tail discards an assignment; an arm …
D60: a tail assignment under a declared non-Unit return yields a read…
D60: a tail assignment under a declared non-Unit return yields a read…