-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Description
The documented else block syntax for handling none values in options fails to parse.
Documented Syntax (from language-reference.md)
var value: int = get_optional() else {
// Handle none case
return -1;
};
Error
When using this syntax, the parser reports multiple errors including:
ExpectedExprExpected(Semicolon)
Reproduction
fn main() {
var opt: option<int> = none;
var value: int = opt else {
0
};
println(value);
}
Expected Behavior
The else block should parse correctly and execute the block when the option is none, using the block's final expression as the value.
Workarounds
Use ?? operator instead:
var value: int = opt ?? 0;
Notes
The ?? operator and ! force unwrap work correctly. Only the else block syntax is affected.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels