Skip to content

'fail' exit from a constructor should be exempt from 'field is never initialized #2845

@gwillen

Description

@gwillen
class foo {
    let x: ();
    new() {
        fail;
    }
}

This shouldn't error with 'field is never initialized'.

The real use case for this is of the form:

new() {
    res = some_operation();
    if res.is_err() {
        fail "This is a specific and helpful error message about the failure of some_operation().";
    } else {
        some_local = res.get();
    }
}

This can be worked around by initializing some_local to a placeholder value, but the type of some_local may not provide a convenient one. It can also be worked around in this specific case by not casing, and just setting some_local = res.get(), at the cost of a less useful error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions