From f81f4066a237409a3d4774b6e193457613e9dc58 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 29 Apr 2024 13:14:51 +0100 Subject: [PATCH] Tweak and comment --- compiler-core/src/type_/expression.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index ed9bfc74b33..17be88b5f9f 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -650,12 +650,17 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ) -> Result { let (fun, args, typ) = self.do_infer_call(fun, args, location)?; - let _ = match fun { + // One common mistake is to think that the syntax for adding a message + // to a `todo` or a `panic` exception is to `todo("...")`, but really + // this does nothing as the `todo` or `panic` throws the exception + // before it gets to the function call `("...")`. + // If we find code doing this then emit a warning. + let todopanic = match fun { TypedExpr::Todo { .. } => Some((location, TodoOrPanic::Todo)), TypedExpr::Panic { .. } => Some((location, TodoOrPanic::Panic)), _ => None, - } - .map(|(location, kind)| { + }; + if let Some((location, kind)) = todopanic { let args_location = match (args.first(), args.last()) { (Some(first), Some(last)) => Some(SrcSpan { start: first.location().start, @@ -663,7 +668,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> { }), _ => None, }; - self.environment .warnings .emit(Warning::TodoOrPanicUsedAsFunction { @@ -672,7 +676,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { args_location, args: args.len(), }); - }); + } Ok(TypedExpr::Call { location,