fix: no need to check exhaustiveness during if/is
This commit is contained in:
		
							parent
							
								
									5024bd3f9c
								
							
						
					
					
						commit
						579abb7d3d
					
				| 
						 | 
				
			
			@ -1672,8 +1672,9 @@ pub enum Warning {
 | 
			
		|||
    },
 | 
			
		||||
 | 
			
		||||
    #[error(
 | 
			
		||||
        "I found an {} that checks an expression with a known type.",
 | 
			
		||||
        "if/is".if_supports_color(Stderr, |s| s.purple())
 | 
			
		||||
        "I found an {} {}",
 | 
			
		||||
        "if/is".if_supports_color(Stderr, |s| s.purple()),
 | 
			
		||||
        "that checks an expression with a known type.".if_supports_color(Stderr, |s| s.yellow())
 | 
			
		||||
    )]
 | 
			
		||||
    #[diagnostic(
 | 
			
		||||
        code("if_is_on_non_data"),
 | 
			
		||||
| 
						 | 
				
			
			@ -1684,7 +1685,7 @@ pub enum Warning {
 | 
			
		|||
    )]
 | 
			
		||||
    UseWhenInstead {
 | 
			
		||||
        #[label(
 | 
			
		||||
            "use {} instead",
 | 
			
		||||
            "use {}",
 | 
			
		||||
            "when/is".if_supports_color(Stderr, |s| s.purple())
 | 
			
		||||
        )]
 | 
			
		||||
        location: Span,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -510,7 +510,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
                    location: _,
 | 
			
		||||
                } = patterns.into_vec().swap_remove(0);
 | 
			
		||||
 | 
			
		||||
                self.infer_assignment(pattern, *value, kind, &annotation, location)
 | 
			
		||||
                self.infer_assignment(pattern, *value, kind, &annotation, location, true)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            UntypedExpr::Trace {
 | 
			
		||||
| 
						 | 
				
			
			@ -1182,6 +1182,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
        kind: UntypedAssignmentKind,
 | 
			
		||||
        annotation: &Option<Annotation>,
 | 
			
		||||
        location: Span,
 | 
			
		||||
        check_exhaustiveness: bool,
 | 
			
		||||
    ) -> Result<TypedExpr, Error> {
 | 
			
		||||
        let typed_value = self.infer(untyped_value.clone())?;
 | 
			
		||||
        let mut value_typ = typed_value.tipo();
 | 
			
		||||
| 
						 | 
				
			
			@ -1239,12 +1240,11 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
        // If `expect` is explicitly used, we still check exhaustiveness but instead of returning an
 | 
			
		||||
        // error we emit a warning which explains that using `expect` is unnecessary.
 | 
			
		||||
        match kind {
 | 
			
		||||
            AssignmentKind::Let { .. } => {
 | 
			
		||||
                self.environment
 | 
			
		||||
                    .check_exhaustiveness(&[&pattern], location, true)?
 | 
			
		||||
            }
 | 
			
		||||
            AssignmentKind::Let { .. } if check_exhaustiveness => self
 | 
			
		||||
                .environment
 | 
			
		||||
                .check_exhaustiveness(&[&pattern], location, true)?,
 | 
			
		||||
 | 
			
		||||
            AssignmentKind::Expect { .. } => {
 | 
			
		||||
            AssignmentKind::Expect { .. } if check_exhaustiveness => {
 | 
			
		||||
                let is_exaustive_pattern = self
 | 
			
		||||
                    .environment
 | 
			
		||||
                    .check_exhaustiveness(&[&pattern], location, false)
 | 
			
		||||
| 
						 | 
				
			
			@ -1292,6 +1292,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
                        });
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            _ => (),
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Ok(TypedExpr::Assignment {
 | 
			
		||||
| 
						 | 
				
			
			@ -1751,6 +1752,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
                    AssignmentKind::expect(),
 | 
			
		||||
                    &annotation,
 | 
			
		||||
                    location,
 | 
			
		||||
                    false,
 | 
			
		||||
                )?
 | 
			
		||||
                else {
 | 
			
		||||
                    unreachable!()
 | 
			
		||||
| 
						 | 
				
			
			@ -1758,7 +1760,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
 | 
			
		|||
 | 
			
		||||
                if !value.tipo().is_data() {
 | 
			
		||||
                    typer.environment.warnings.push(Warning::UseWhenInstead {
 | 
			
		||||
                        location: branch.location,
 | 
			
		||||
                        location: branch.condition.location().union(location),
 | 
			
		||||
                    })
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue