Skip to content

Commit

Permalink
Tweak and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Apr 29, 2024
1 parent 8810a03 commit f81f406
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions compiler-core/src/type_/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,20 +650,24 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
) -> Result<TypedExpr, Error> {
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,
end: last.location().end,
}),
_ => None,
};

self.environment
.warnings
.emit(Warning::TodoOrPanicUsedAsFunction {
Expand All @@ -672,7 +676,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
args_location,
args: args.len(),
});
});
}

Ok(TypedExpr::Call {
location,
Expand Down

0 comments on commit f81f406

Please sign in to comment.