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.
DCA now detects dead code when all branches return explicitly. (FuelL…
…abs#4169) Fixing `If` was straightforward. But that didn't automatically the fix `match` scenario (see test case). Turns out that `match` always has a covering "ImplicitReturn" expression, and with implicit returns in DCA, we add an edge from the beginning to the end, which I couldn't figure out why. Just removing that got it working. I request the reviewers to validate this part of the change carefully. Closes FuelLabs#2313 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] 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.
- Loading branch information
1 parent
9346bf4
commit 253d6af
Showing
5 changed files
with
55 additions
and
7 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
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/dca/all_paths_return/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,8 @@ | ||
[[package]] | ||
name = 'all_paths_return' | ||
source = 'member' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F8249D11C4071B26' |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/dca/all_paths_return/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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "all_paths_return" | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } |
28 changes: 28 additions & 0 deletions
28
test/src/e2e_vm_tests/test_programs/should_pass/dca/all_paths_return/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,28 @@ | ||
script; | ||
|
||
fn if_f() -> u64 { | ||
if true { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
// should trigger a warning | ||
return 2; | ||
} | ||
|
||
fn match_f() -> u64 { | ||
match 10 { | ||
1 => return 8, | ||
_ => return 3, | ||
} | ||
// should trigger a warning | ||
return 21; | ||
} | ||
|
||
fn main() -> u64 { | ||
if true { | ||
return if_f(); | ||
} else { | ||
return match_f(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_pass/dca/all_paths_return/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,7 @@ | ||
category = "compile" | ||
|
||
# check: $()return 2; | ||
# nextln: $()This code is unreachable. | ||
|
||
# check: $()return 21; | ||
# nextln: $()This code is unreachable. |