modular
modular copied to clipboard
[Feature Request] Constrained[False], or alternative, should not cause a return expected error
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the 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
Messed up the PR a few times but it's done now