Skip to content

Commit

Permalink
Disallow async calls using non-async methods
Browse files Browse the repository at this point in the history
Async calls using the `async x.y` syntax now ensure that `y` is actually
an async method, instead of (incorrectly) allowing any method to be
used.

Changelog: fixed
  • Loading branch information
yorickpeterse committed Oct 22, 2022
1 parent ea303b4 commit efdc646
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion compiler/src/type_check/expressions.rs
Expand Up @@ -3916,7 +3916,8 @@ impl<'a> CheckMethodBody<'a> {

if !matches!(
rec_id,
TypeId::ClassInstance(ins) if ins.instance_of().kind(self.db()).is_async()
TypeId::ClassInstance(ins)
if ins.instance_of().kind(self.db()).is_async()
) {
let rec_name =
format_type_with_self(self.db(), self.self_type, rec_type);
Expand All @@ -3931,6 +3932,17 @@ impl<'a> CheckMethodBody<'a> {
return TypeRef::Error;
}

if !method.is_async(self.db()) {
self.state.diagnostics.error(
DiagnosticId::InvalidCall,
format!("'{}' isn't an async method", name),
self.file(),
node.name.location.clone(),
);

return TypeRef::Error;
}

let mut call =
MethodCall::new(self.state, self.module, rec_type, rec_id, method);

Expand Down

0 comments on commit efdc646

Please sign in to comment.