diff --git a/src/typ/error.rs b/src/typ/error.rs index 53e944a07af..e527e9ac0c4 100644 --- a/src/typ/error.rs +++ b/src/typ/error.rs @@ -218,6 +218,8 @@ pub enum Warning { Todo { location: SrcSpan }, ImplicitlyDiscardedResult { location: SrcSpan }, + + NoFieldsRecordUpdate { location: SrcSpan }, } #[derive(Debug, PartialEq)] diff --git a/src/typ/expr.rs b/src/typ/expr.rs index dfcc339fbfe..4b549628444 100644 --- a/src/typ/expr.rs +++ b/src/typ/expr.rs @@ -1289,6 +1289,14 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ) .collect::>()?; + if args.is_empty() { + self.environment + .warnings + .push(Warning::NoFieldsRecordUpdate { + location: location.clone(), + }); + } + return Ok(TypedExpr::RecordUpdate { location, typ: spread.typ(), diff --git a/src/typ/tests.rs b/src/typ/tests.rs index a74cface007..c69038d1b2e 100644 --- a/src/typ/tests.rs +++ b/src/typ/tests.rs @@ -2952,6 +2952,35 @@ fn main() { foo(); 5 }", fn foo() { Ok(5) } fn main() { let _ = foo(); 5 }", ); + + // Some fields are given in a record update do not emit warnings + assert_no_warnings!( + " + pub type Person { + Person(name: String, age: Int) + }; + pub fn update_person() { + let past = Person(\"Quinn\", 27) + let present = Person(..past, name: \"Santi\") + present + }", + ); + + // No fields are given in a record update emit warnings + assert_warning!( + " + pub type Person { + Person(name: String, age: Int) + }; + pub fn update_person() { + let past = Person(\"Quinn\", 27) + let present = Person(..past) + present + }", + Warning::NoFieldsRecordUpdate { + location: SrcSpan { start: 183, end: 197 } + } + ); } fn env_types_with(things: &[&str]) -> Vec { diff --git a/src/warning.rs b/src/warning.rs index 5b728b86944..aacd2e7e1ee 100644 --- a/src/warning.rs +++ b/src/warning.rs @@ -49,6 +49,17 @@ impl Warning { write(buffer, diagnostic, Severity::Warning); writeln!(buffer, "The Result value returned by this code is not being used, so any error is being silently ignored. Check for an error with a case statement, or assign it to the variable _ if you are sure the error does not matter.").unwrap(); } + NoFieldsRecordUpdate { location } => { + let diagnostic = Diagnostic { + title: "No fields are given in a record update".to_string(), + label: "".to_string(), + file: path.to_str().unwrap().to_string(), + src: src.to_string(), + location: location.clone(), + }; + write(buffer, diagnostic, Severity::Warning); + writeln!(buffer, "The Record Update in this code is no fields are given.").unwrap(); + } }, } }