From a073a95f6b69297e132064a285a6127134daa45f Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Tue, 17 Sep 2024 13:04:13 +0100 Subject: [PATCH] Fixes OOB in type_check_analyze of ImplTrait. (#6551) ## Description An unused line of code threw an OOB panic because of a parser error. Removing the unused line of code fixes the issue. Fixes #6331 ## 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). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [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: Joshua Batty --- .../ast_node/declaration/impl_trait.rs | 3 +-- .../mismatch_closing_delimiters/Forc.lock | 8 ++++++++ .../mismatch_closing_delimiters/Forc.toml | 9 +++++++++ .../mismatch_closing_delimiters/src/main.sw | 14 ++++++++++++++ .../mismatch_closing_delimiters/test.toml | 4 ++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/test.toml diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index 15266d2d2a7..5d47d1616d7 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -1629,8 +1629,7 @@ impl TypeCheckAnalysis for ty::ImplSelfOrTrait { ctx.push_nodes_for_impl_trait(self); // Now lets analyze each impl trait item. - for (i, item) in impl_trait.items.iter().enumerate() { - let _node = ctx.items_node_stack[i]; + for item in impl_trait.items.iter() { item.type_check_analyze(handler, ctx)?; } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.lock new file mode 100644 index 00000000000..a0991ddd91b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.lock @@ -0,0 +1,8 @@ +[[package]] +name = "core" +source = "path+from-root-F62FA9D54ABC8F01" + +[[package]] +name = "mismatch_closing_delimiters" +source = "member" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.toml new file mode 100644 index 00000000000..084875b06eb --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "mismatch_closing_delimiters" +entry = "main.sw" +implicit-std = false + +[dependencies] +core = { path = "../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/src/main.sw new file mode 100644 index 00000000000..22272bdf326 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/src/main.sw @@ -0,0 +1,14 @@ +script; + +struct Struct{x:u} +impl Struct{ + fn w()->f{{(()}} + trait Supertrait{} + impl Supertrait for Struct{) +} + +fn s(b:B) where A:t{}fn n(){} + +fn main() -> u64 { + 0 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/test.toml new file mode 100644 index 00000000000..e3280310725 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/mismatch_closing_delimiters/test.toml @@ -0,0 +1,4 @@ +category = "fail" + +# check: $()fn w()->f{{(()}} +# nextln: $()mismatched delimiters