@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
ast::{Definition, ModuleKind, TraceLevel, Tracing, TypedModule, UntypedModule},
|
||||
ast::{Definition, ModuleKind, Pattern, TraceLevel, Tracing, TypedModule, UntypedModule},
|
||||
builtins,
|
||||
expr::TypedExpr,
|
||||
parser,
|
||||
@@ -2720,3 +2720,44 @@ fn if_soft_cast_not_data() {
|
||||
|
||||
assert!(matches!(warnings[0], Warning::UseWhenInstead { .. }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn side_effects() {
|
||||
let source_code = r#"
|
||||
pub fn side_effects() {
|
||||
trace "Aiken, rocks!"
|
||||
Void
|
||||
}
|
||||
|
||||
pub fn foo() {
|
||||
expect _ = side_effects()
|
||||
True
|
||||
}
|
||||
"#;
|
||||
|
||||
let (warnings, ast) = check(parse(source_code)).unwrap();
|
||||
|
||||
assert!(warnings.is_empty(), "no warnings: {warnings:#?}");
|
||||
|
||||
if let Some(Definition::Fn(ref foo)) = ast.definitions().last() {
|
||||
if let TypedExpr::Sequence {
|
||||
ref expressions, ..
|
||||
} = foo.body
|
||||
{
|
||||
matches!(
|
||||
expressions[..],
|
||||
[
|
||||
TypedExpr::Assignment {
|
||||
pattern: Pattern::Discard { .. },
|
||||
..
|
||||
},
|
||||
TypedExpr::Var { .. },
|
||||
],
|
||||
);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1251,7 +1251,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||
.check_exhaustiveness(&[&pattern], location, false)
|
||||
.is_ok();
|
||||
|
||||
if !value_is_data && is_exaustive_pattern {
|
||||
if !value_is_data && is_exaustive_pattern && !pattern.is_discard() {
|
||||
self.environment
|
||||
.warnings
|
||||
.push(Warning::SingleConstructorExpect {
|
||||
|
||||
Reference in New Issue
Block a user