Skip to content

Bug: Option 'else' block syntax fails to parse #45

@mjm918

Description

@mjm918

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:

  • ExpectedExpr
  • Expected(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions