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 bug where trait/abi method argument type mismatch went uncaught (F…
…uelLabs#1581) * Fix bug where trait/abi method argument type mismatch went uncaught Closes FuelLabs#1327. Turns out unification was already catching this, but the produced error was never returned from the trait impl checking function :D It looks like a new `Vec` was introduced at one point to collect errors in order to work around ownership issues involved with some fancy uses of `iter().find_map()`, however these errors were never collected from the outer scope. I've refactored this section to use basic for loops and control flow instead which makes it easier for Rust to reason about ownership over the top-level `errors` Vec and reduces the need for the extra error-collecting `Vec`s. Also adds two new `should_fail` tests to verify that we produce errors when argument types differ between implementation and trait/abi declaration. * Avoid searching for trait fn decl twice by changing checklist to a map
- Loading branch information
1 parent
e89bb84
commit a582acf
Showing
9 changed files
with
114 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,7 +330,6 @@ impl Engine { | |
} else { | ||
expected | ||
}; | ||
|
||
self.unify(received, expected, span, help_text) | ||
} | ||
|
||
|
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_fail/abi_method_signature_mismatch/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 = 'abi_method_signature_mismatch' | ||
dependencies = [] |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_fail/abi_method_signature_mismatch/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]>"] | ||
license = "Apache-2.0" | ||
name = "abi_method_signature_mismatch" | ||
entry = "main.sw" | ||
implicit-std = false |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_fail/abi_method_signature_mismatch/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,14 @@ | ||
// This should result in an error saying that the method signature of the | ||
// implementation does not match the declaration. | ||
|
||
contract; | ||
|
||
abi MyContract { | ||
fn foo(x: u64) -> str[7]; | ||
} | ||
|
||
impl MyContract for Contract { | ||
fn foo(s: str[7]) -> str[7] { | ||
s | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/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 = 'trait_method_signature_mismatch' | ||
dependencies = [] |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/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]>"] | ||
license = "Apache-2.0" | ||
name = "trait_method_signature_mismatch" | ||
entry = "main.sw" | ||
implicit-std = false |
18 changes: 18 additions & 0 deletions
18
test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/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,18 @@ | ||
// This should result in an error saying that the method signature of the | ||
// implementation does not match the declaration. | ||
|
||
library test; | ||
|
||
trait Foo { | ||
fn foo(x: u64) -> str[7]; | ||
} | ||
|
||
struct S { | ||
x: u64, | ||
} | ||
|
||
impl Foo for S { | ||
fn foo(s: str[7]) -> str[7] { | ||
s | ||
} | ||
} |