fix: no single when clause warning sometimes

While looking at some code, I noticed that this
warning would show up even if an error for a
non-exhaustive when/is shows up for the same when/is
expression. This isn't a useful situation to show this
warning because things are not exhaustive yet so we should
let the user finish and only provide the errors. If things
are exhaustive then the code proceeds and if a warning was set
when there's only one clause pattern then this warning message
can be pushed because that's when it's actually useful.
This commit is contained in:
rvcas
2024-02-13 20:12:40 -05:00
parent 4c5a449d83
commit 3582c5569d

View File

@@ -1962,8 +1962,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
) -> Result<TypedExpr, Error> {
// if there is only one clause we want to present a warning
// that suggests that a `let` binding should be used instead.
if clauses.len() == 1 {
self.environment.warnings.push(Warning::SingleWhenClause {
let mut sample = None;
if clauses.len() == 1 && clauses[0].patterns.len() == 1 {
sample = Some(Warning::SingleWhenClause {
location: clauses[0].patterns[0].location(),
sample: UntypedExpr::Assignment {
location: Span::empty(),
@@ -1996,6 +1998,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
self.check_when_exhaustiveness(&typed_clauses, location)?;
if let Some(sample) = sample {
self.environment.warnings.push(sample);
}
Ok(TypedExpr::When {
location,
tipo: return_type,