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
parse_if_let fabricates else: 0 for a missing else #1179
Bug. An if let with no else is desugared to else: 0. The value is fabricated:
if let Some(v) = f(): seen = v types as i32 vs i32 and compiles by accident.
if let Some(v) = f(): assert(v == 7) fails as i32 vs Unit although the user wrote no i32. lldb at Sema.merge_contextual_owned_join_types: w1 = 14 (Unit), w2 = 3 (i32).
An unannotated function whose whole body is an else-less if let with an assignment body infers i32 and returns 0 when the pattern does not match (run: prints 0).
This is a silent fallback (CLAUDE.md, No Silent Fallbacks).
Fix. Desugar a missing else to an empty block, as the guard-let path in the same file already does. No value is fabricated; what a missing else means is D43's and §9.1's business.
Must not land alone. With only this change, a single-statement unannotated body if let P = e: x = v stops compiling (the literal 0 was joining with the i32-typed assignment). It lands in the same batch as D43's missing-arm rule.
Tests.
Else-less if let tail with a Unit body on an unannotated fn: function is Unit; both match and no-match paths run.
Else-less if let tail with a value/assignment body: function is Unit; a caller that consumes the result is a compile error; the no-match path does not produce 0.
Activity