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