Report unsuffixed record literal field with effectful function

This commit is contained in:
Agus Zubiaga 2024-10-22 19:50:32 -03:00
parent ea35094b28
commit 215de707fa
No known key found for this signature in database
7 changed files with 121 additions and 21 deletions

View file

@ -6,7 +6,7 @@ use crate::abilities::SpecializationId;
use crate::exhaustive::{ExhaustiveContext, SketchedRows};
use crate::expected::{Expected, PExpected};
use roc_collections::soa::{index_push_new, slice_extend_new};
use roc_module::ident::TagName;
use roc_module::ident::{IdentSuffix, TagName};
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use roc_types::subs::{ExhaustiveMark, IllegalCycleMark, Variable};
@ -597,6 +597,15 @@ impl Constraints {
Constraint::FxCall(constraint_index)
}
pub fn check_record_field_fx(
&self,
suffix: IdentSuffix,
variable: Variable,
region: Region,
) -> Constraint {
Constraint::CheckRecordFieldFx(suffix, variable, region)
}
pub fn contains_save_the_environment(&self, constraint: &Constraint) -> bool {
match constraint {
Constraint::SaveTheEnvironment => true,
@ -623,6 +632,7 @@ impl Constraints {
| Constraint::Pattern(..)
| Constraint::EffectfulStmt(..)
| Constraint::FxCall(_)
| Constraint::CheckRecordFieldFx(_, _, _)
| Constraint::FlexToPure(_)
| Constraint::True
| Constraint::IsOpenType(_)
@ -798,10 +808,12 @@ pub enum Constraint {
),
/// Check call fx against enclosing function fx
FxCall(Index<FxCallConstraint>),
/// Mark a function that doesn't call any effectful functions as pure
/// Set an fx var as pure if flex (no effectful functions were called)
FlexToPure(Variable),
/// Expect statement to be effectful
EffectfulStmt(Variable, Region),
/// Require field name to be accurately suffixed
CheckRecordFieldFx(IdentSuffix, Variable, Region),
/// Used for things that always unify, e.g. blanks and runtime errors
True,
SaveTheEnvironment,
@ -919,6 +931,9 @@ impl std::fmt::Debug for Constraint {
Self::FlexToPure(arg0) => {
write!(f, "FlexToPure({arg0:?})")
}
Self::CheckRecordFieldFx(arg0, arg1, arg2) => {
write!(f, "CheckRecordFieldFx({arg0:?}, {arg1:?}, {arg2:?})")
}
Self::True => write!(f, "True"),
Self::SaveTheEnvironment => write!(f, "SaveTheEnvironment"),
Self::Let(arg0, arg1) => f.debug_tuple("Let").field(arg0).field(arg1).finish(),