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.
Fix DCA warnings for unused struct fields in contracts. (FuelLabs#3562)
If a struct type is used as a return type in the interface surface of the contract, then assume that any fields inside the struct can be used outside of the contract. Closes FuelLabs#1305.
- Loading branch information
Showing
17 changed files
with
193 additions
and
4 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
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field/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 = 'unused_struct_field' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field/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" | ||
implicit-std = false | ||
license = "Apache-2.0" | ||
name = "unused_struct_field" |
15 changes: 15 additions & 0 deletions
15
test/src/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field/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,15 @@ | ||
contract; | ||
|
||
struct S { | ||
x: u64, | ||
} | ||
|
||
abi MyContract { | ||
fn foo(s: S) -> S; | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn foo(s: S) -> S { | ||
s | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field/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,3 @@ | ||
category = "compile" | ||
|
||
# not: $()This struct field is never accessed. |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_array/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 = 'unused_struct_field_array' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_array/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" | ||
implicit-std = false | ||
license = "Apache-2.0" | ||
name = "unused_struct_field_array" |
15 changes: 15 additions & 0 deletions
15
...e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_array/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,15 @@ | ||
contract; | ||
|
||
struct S { | ||
x: u64, | ||
} | ||
|
||
abi MyContract { | ||
fn foo(s: S) -> [S; 1]; | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn foo(s: S) -> [S; 1] { | ||
[s] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_array/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,3 @@ | ||
category = "compile" | ||
|
||
# not: $()This struct field is never accessed. |
3 changes: 3 additions & 0 deletions
3
...rc/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_enum/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 = 'unused_struct_field_enum' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
...rc/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_enum/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" | ||
implicit-std = false | ||
license = "Apache-2.0" | ||
name = "unused_struct_field_enum" |
19 changes: 19 additions & 0 deletions
19
.../e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_enum/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,19 @@ | ||
contract; | ||
|
||
struct S { | ||
x: u64, | ||
} | ||
|
||
enum E { | ||
A: S, | ||
} | ||
|
||
abi MyContract { | ||
fn foo(s: S) -> E; | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn foo(s: S) -> E { | ||
E::A(s) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...rc/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_enum/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,3 @@ | ||
category = "compile" | ||
|
||
# not: $()This struct field is never accessed. |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_tuple/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 = 'unused_struct_field_tuple' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_tuple/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" | ||
implicit-std = false | ||
license = "Apache-2.0" | ||
name = "unused_struct_field_tuple" |
15 changes: 15 additions & 0 deletions
15
...e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_tuple/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,15 @@ | ||
contract; | ||
|
||
struct S { | ||
x: u64, | ||
} | ||
|
||
abi MyContract { | ||
fn foo(s: S) -> (S); | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn foo(s: S) -> (S) { | ||
(s) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/dca/contract/unused_struct_field_tuple/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,3 @@ | ||
category = "compile" | ||
|
||
# not: $()This struct field is never accessed. |