-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and fix overlapping trait impls.
find_method_for_type now if we have: impl<T> FromBytes for T and: impl FromBytes for DataPoint, we pick the second implementation. Fixes #6572
- Loading branch information
Showing
5 changed files
with
107 additions
and
15 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
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_pass/language/overlapped_trait_impls/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,13 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-BB2447E2F19FD755" | ||
|
||
[[package]] | ||
name = "overlapped_trait_impls" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-BB2447E2F19FD755" | ||
dependencies = ["core"] |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_pass/language/overlapped_trait_impls/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,9 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
license = "Apache-2.0" | ||
name = "overlapped_trait_impls" | ||
entry = "main.sw" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
49 changes: 49 additions & 0 deletions
49
test/src/e2e_vm_tests/test_programs/should_pass/language/overlapped_trait_impls/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,49 @@ | ||
script; | ||
|
||
use std::{ | ||
bytes::Bytes, | ||
vec::Vec, | ||
}; | ||
|
||
pub trait FromBytesConvertible { | ||
fn _from_be_bytes(bytes: Bytes) -> Self; | ||
} | ||
|
||
pub trait FromBytes { | ||
fn from_bytes(bytes: Bytes) -> Self; | ||
} | ||
|
||
impl<T> FromBytes for T | ||
where | ||
T: FromBytesConvertible, | ||
{ | ||
fn from_bytes(bytes: Bytes) -> Self { | ||
Self::_from_be_bytes(bytes) | ||
} | ||
} | ||
|
||
pub struct DataPoint {} | ||
pub struct Payload {} | ||
|
||
impl FromBytes for DataPoint { | ||
fn from_bytes(bytes: Bytes) -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl Payload { | ||
pub fn from_bytes(bytes: Bytes) { | ||
let mut data_points = Vec::new(); | ||
|
||
data_points.push(DataPoint::from_bytes(bytes)); | ||
|
||
let a:DataPoint = DataPoint::from_bytes(bytes); | ||
data_points.push(a); | ||
} | ||
} | ||
|
||
pub fn main() -> bool { | ||
Payload::from_bytes(Bytes::new()); | ||
|
||
true | ||
} |
5 changes: 5 additions & 0 deletions
5
test/src/e2e_vm_tests/test_programs/should_pass/language/overlapped_trait_impls/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,5 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 1 } | ||
expected_result_new_encoding = { action = "return_data", value = "01" } | ||
validate_abi = false | ||
expected_warnings = 3 |