modular icon indicating copy to clipboard operation
modular copied to clipboard

[Feature Request] Constrained[False], or alternative, should not cause a return expected error

Open Benny-Nottonson opened this issue 1 year ago • 1 comments

Review Mojo's priorities

What is your request?

Example Code

fn expand_type[Type: DType]() -> DType:
    @parameter
    if Type.is_floating_point():
        return DType.float64
    elif Type.is_signed():
        return DType.int64
    elif Type.is_integral():
        return DType.uint64
        
    constrained[False, "Type must be numeric"]()

The following code should NOT cause a "return expected at end of function with results" compilation error.

Along with this, there should really just be unreachable.

What is your motivation for this change?

If Mojo is allowing compile time verification of inputs to a function, it makes sense that extra code to return an invalid value should not be required, as the code added can by nature never run.

Any other details?

No response

Benny-Nottonson avatar May 06 '24 02:05 Benny-Nottonson

Messed up the PR a few times but it's done now

Benny-Nottonson avatar May 06 '24 02:05 Benny-Nottonson