-
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.
Fixes generic trait methods not found.
The issue this commit solves is the method not found error thrown when when we try to use generic traits. This issue was fixed by adding support to the `unify_check` so left types can match right types `UnknownGeneric`. We also check that the left type implemnts the trait constraints of the `UnknownGeneric` before return true. Fixes #4806 Unblocks #4701
- Loading branch information
Showing
15 changed files
with
226 additions
and
13 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
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_fail/generic_traits_with_bounds/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-784776BEEA3D86B0' | ||
|
||
[[package]] | ||
name = 'generic_traits_with_bounds' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-784776BEEA3D86B0' | ||
dependencies = ['core'] |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_fail/generic_traits_with_bounds/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] | ||
name = "generic_traits_with_bounds" | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
23 changes: 23 additions & 0 deletions
23
...rc/e2e_vm_tests/test_programs/should_fail/generic_traits_with_bounds/json_abi_oracle.json
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,23 @@ | ||
{ | ||
"functions": [ | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "main", | ||
"output": { | ||
"name": "", | ||
"type": 0, | ||
"typeArguments": null | ||
} | ||
} | ||
], | ||
"loggedTypes": [], | ||
"types": [ | ||
{ | ||
"components": null, | ||
"type": "u64", | ||
"typeId": 0, | ||
"typeParameters": null | ||
} | ||
] | ||
} |
26 changes: 26 additions & 0 deletions
26
test/src/e2e_vm_tests/test_programs/should_fail/generic_traits_with_bounds/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,26 @@ | ||
script; | ||
|
||
use std::assert::*; | ||
|
||
trait Trait { | ||
fn method(self) -> u64; | ||
} | ||
|
||
impl<A, B> Trait for (A, B) where A: Trait, B: Trait { | ||
fn method(self) -> u64 { | ||
self.0.method() + self.1.method() | ||
} | ||
} | ||
|
||
/* Without this (1, 2).method() should not be found | ||
impl Trait for u64 { | ||
fn method(self) -> u64 { | ||
self | ||
} | ||
} | ||
*/ | ||
|
||
fn main() -> bool { | ||
assert((1,2).method() == 3); | ||
true | ||
} |
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_fail/generic_traits_with_bounds/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,4 @@ | ||
category = "fail" | ||
|
||
# check: $()assert((1,2).method() == 3); | ||
# nextln: $()No method named "method" found for type "(u64, u64)". |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_pass/language/generic_tuple_trait/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-AA4B286930BA1707' | ||
|
||
[[package]] | ||
name = 'generic_where_in_impl_self' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-AA4B286930BA1707' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/language/generic_tuple_trait/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 <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "generic_tuple_trait" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
25 changes: 25 additions & 0 deletions
25
.../e2e_vm_tests/test_programs/should_pass/language/generic_tuple_trait/json_abi_oracle.json
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,25 @@ | ||
{ | ||
"configurables": [], | ||
"functions": [ | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "main", | ||
"output": { | ||
"name": "", | ||
"type": 0, | ||
"typeArguments": null | ||
} | ||
} | ||
], | ||
"loggedTypes": [], | ||
"messagesTypes": [], | ||
"types": [ | ||
{ | ||
"components": null, | ||
"type": "bool", | ||
"typeId": 0, | ||
"typeParameters": null | ||
} | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
test/src/e2e_vm_tests/test_programs/should_pass/language/generic_tuple_trait/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,35 @@ | ||
script; | ||
|
||
use std::assert::*; | ||
|
||
trait Trait { | ||
fn method(self) -> u64; | ||
} | ||
|
||
trait Trait2 { | ||
fn method2(self) -> u64; | ||
} | ||
|
||
impl<A, B> Trait for (A, B) { | ||
fn method(self) -> u64 { | ||
42 | ||
} | ||
} | ||
|
||
impl Trait2 for u64 { | ||
fn method2(self) -> u64 { | ||
self | ||
} | ||
} | ||
|
||
impl<A, B> Trait2 for (A, B) where A: Trait2, B: Trait2 { | ||
fn method2(self) -> u64 { | ||
self.0.method2() + self.1.method2() | ||
} | ||
} | ||
|
||
fn main() -> bool { | ||
assert((1,2).method() == 42); | ||
assert((1,2).method2() == 3); | ||
true | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/language/generic_tuple_trait/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 = "run" | ||
expected_result = { action = "return", value = 1 } | ||
validate_abi = true |