Skip to content

Commit

Permalink
Improves error handling of method application args type checking. (#5717
Browse files Browse the repository at this point in the history
)

## Description
In some cases args type checking is returning an error in the handler
but not in the result.
With this fix we check the handler for errors too.

Fixes #5659

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: João Matos <joao@tritao.eu>
  • Loading branch information
esdrubal and tritao authored Mar 12, 2024
1 parent 64d5398 commit a099f34
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ pub(crate) fn type_check_method_application(
} else {
// Ignore errors in method parameters
// On the second pass we will throw the errors if they persist.
let h = Handler::default();
args_opt_buf.push_back(ty::TyExpression::type_check(&h, ctx, arg.clone()).ok());
let arg_handler = Handler::default();
let arg_opt = ty::TyExpression::type_check(&arg_handler, ctx, arg.clone()).ok();
if arg_handler.has_errors() {
args_opt_buf.push_back(None);
} else {
args_opt_buf.push_back(arg_opt);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "method_type_args_variable_non_existing"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "method_type_args_variable_non_existing"
entry = "main.sw"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
script;

struct S {}

impl S {
fn method(self, a: u64) -> u64 {
a
}
}

fn main() {
let _ = S {}.method(non_existing);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()let _ = S {}.method(non_existing);
# nextln: $()Variable "non_existing" does not exist in this scope.

0 comments on commit a099f34

Please sign in to comment.