Skip to content

bare returns issues #23

Description

@jersmi7

Is your feature request related to a problem? Please describe.
Bare return can give the Lyte checker trouble, but it is unclear why -- unsupported syntax, incomplete feature, or a type-checking/codegen issue?

Describe the solution you'd like
If bare return is intentionally unsupported, Lyte should report a clearer error, such as "return requires an explicit value." It would also help to clarify the intended pattern for early exits.

Describe alternatives you've considered
I think it works to use explicit return values like return 0, return false, or return nil, which makes sense to Lyte's lean towards the literal. May simply need a clearer diagnostic and documentation.

Something like these are in play:

// 1. Bare return in a void helper: currently problematic
do_work() {
    if done {
        return
    }
    value = value + 1
}

// 2. Explicit return value in a value-returning helper: works as expected
clamp01(x: f32) -> f32 {
    if x < 0.0 { return 0.0 }
    if x > 1.0 { return 1.0 }
    x
}

// 3. Branching workaround for void helpers
do_work_safe() {
    if !done {
        value = value + 1
    }
}

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