forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements DCA warnings for function parameters. (FuelLabs#4406)
## Description With these changes we will have DCA warnings for function parameters. This PR also fixes tests that have unused function parameters. ## Checklist - [ ] 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: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
cd936a5
commit dcb7917
Showing
30 changed files
with
231 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_fail/simple_generics/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[package]] | ||
name = 'func_param' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "func_param" | ||
implicit-std = false |
38 changes: 38 additions & 0 deletions
38
test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
script; | ||
|
||
|
||
// Param `i` should have no warnings as `d` is still using it | ||
fn unused_fn(i: u64) { | ||
let d = i; | ||
} | ||
|
||
fn f(i: u64) { | ||
} | ||
|
||
struct A {} | ||
|
||
impl A { | ||
fn g(i: u64) { | ||
} | ||
|
||
fn h(self, i: u64) { | ||
} | ||
} | ||
|
||
fn i(_p: u64) { | ||
} | ||
|
||
fn j(ref mut foo: u64) { | ||
foo = 42; | ||
} | ||
|
||
fn main() { | ||
f(42); | ||
A::g(42); | ||
let a = A{}; | ||
a.h(42); | ||
i(42); | ||
|
||
let mut foo = 42; | ||
j(foo); | ||
} |
19 changes: 19 additions & 0 deletions
19
test/src/e2e_vm_tests/test_programs/should_pass/dca/func_param/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
category = "compile" | ||
|
||
# check: $()fn unused_fn(i: u64) { | ||
# nextln: $()This function is never called. | ||
# nextln: $()let d = i; | ||
|
||
# check: $()let d = i; | ||
# nextln: $()This declaration is never used. | ||
|
||
# check: $()fn f(i: u64) { | ||
# nextln: $()This declaration is never used. | ||
|
||
# check: $()fn g(i: u64) { | ||
# nextln: $()This declaration is never used. | ||
|
||
# check: $()fn h(self, i: u64) { | ||
# nextln: $()This declaration is never used. | ||
|
||
expected_warnings = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ struct Bar { | |
value: u64 | ||
} | ||
|
||
fn internal_fn(s: Bar) { | ||
fn internal_fn(_s: Bar) { | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ pub struct Foo { | |
value: u64 | ||
} | ||
|
||
pub fn external_fn(s: Foo) { | ||
pub fn external_fn(_s: Foo) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.