From 3582c5569dcf72c735d07282895293f3e944a376 Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 13 Feb 2024 20:12:40 -0500 Subject: [PATCH] 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. --- crates/aiken-lang/src/tipo/expr.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index ccc403e9..83e55f33 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -1962,8 +1962,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ) -> Result { // 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,