elige pattern type mismatch
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
A switch case literal must unify with the scrutinee type.
Syntax: switch level { case 1 { } case \"high\" { } default { } }
Category#
control-flow
Related#
Examples#
radix/corpus/elige/pattern-type-reject.fab (canonical · reject)#
A switch case literal must unify with the scrutinee type.
# =============================================================================
# switch pattern type mismatch — a case literal types against its scrutinee
# =============================================================================
# Every case literal is checked against the type of the scrutinee. This
# switch is over an int, but its second arm claims a string, so the check
# reports SEM010 with the issue pattern_type_mismatch instead of building
# an arm that can never run.
fn gate(int level) → string {
switch level {
case 1 {
return "low"
}
case "high" {
return "high"
}
default {
return "other"
}
}
}
main {
print gate(1)
}Expected: compilation rejects this example.