Allow ignored defs with an effectful RHS

This commit is contained in:
Agus Zubiaga 2024-10-24 00:24:49 -03:00
parent 175a2b5683
commit c9f001b041
No known key found for this signature in database
13 changed files with 136 additions and 126 deletions

View file

@ -1189,14 +1189,6 @@ pub fn can_problem<'b>(
]);
title = "NAME NOT BOUND IN ALL PATTERNS".to_string();
}
Problem::NoIdentifiersIntroduced(region) => {
doc = alloc.stack([
alloc.reflow("This destructure assignment doesn't introduce any new variables:"),
alloc.region(lines.convert_region(region), severity),
alloc.reflow("If you don't need to use the value on the right-hand-side of this assignment, consider removing the assignment. Since Roc is purely functional, assignments that don't introduce variables cannot affect a program's behavior!"),
]);
title = "UNNECESSARY DEFINITION".to_string();
}
Problem::OverloadedSpecialization {
ability_member,
overload,

View file

@ -4,7 +4,7 @@ use crate::error::canonicalize::{to_circular_def_doc, CIRCULAR_DEF};
use crate::report::{Annotation, Report, RocDocAllocator, RocDocBuilder};
use itertools::EitherOrBoth;
use itertools::Itertools;
use roc_can::constraint::{FxCallKind, FxSuffixKind};
use roc_can::constraint::{ExpectEffectfulReason, FxCallKind, FxSuffixKind};
use roc_can::expected::{Expected, PExpected};
use roc_collections::all::{HumanIndex, MutSet, SendMap};
use roc_collections::VecMap;
@ -368,7 +368,7 @@ pub fn type_problem<'b>(
severity,
})
}
PureStmt(region) => {
ExpectedEffectful(region, ExpectEffectfulReason::Stmt) => {
let stack = [
alloc.reflow("This statement does not produce any effects:"),
alloc.region(lines.convert_region(region), severity),
@ -384,6 +384,20 @@ pub fn type_problem<'b>(
severity,
})
}
ExpectedEffectful(region, ExpectEffectfulReason::Ignored) => {
let stack = [
alloc.reflow("This assignment doesn't introduce any new variables:"),
alloc.region(lines.convert_region(region), severity),
alloc.reflow("Since it doesn't call any effectful functions, this assignment cannot affect the program's behavior. If you don't need to use the value on the right-hand-side, consider removing the assignment.")
];
Some(Report {
title: "UNNECESSARY DEFINITION".to_string(),
filename,
doc: alloc.stack(stack),
severity,
})
}
UnsuffixedEffectfulFunction(
region,
kind @ (FxSuffixKind::Let(symbol) | FxSuffixKind::Pattern(symbol)),
@ -5522,5 +5536,6 @@ fn describe_fx_call_kind<'b>(
]),
FxCallKind::Call(None) => alloc.reflow("This expression calls an effectful function:"),
FxCallKind::Stmt => alloc.reflow("This statement calls an effectful function:"),
FxCallKind::Ignored => alloc.reflow("This ignored def calls an effectful function:"),
}
}