-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Check for type aliases when implementing traits #6875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tritao
merged 14 commits into
master
from
jjcnn/unalias_type_id_in_trait_map_unification
Mar 6, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bdfea6d
Added testcase
jjcnn 7e268f7
Improved error message when implementing duplicate impls for aliased …
jjcnn c85d708
Removed TODO
jjcnn 5f5a23d
Improve remaining error messages in TraitMap::insert
jjcnn a2f67bf
Expected test output
jjcnn 4cd928e
clippy, fmt
jjcnn c2794c6
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
jjcnn 9715400
Fixed failing tests
jjcnn 1edf786
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
jjcnn cdd2051
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
IGI-111 dff9251
Untabify
jjcnn 6e60c67
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
jjcnn b3cef9e
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
jjcnn 05322d7
Merge branch 'master' into jjcnn/unalias_type_id_in_trait_map_unifica…
JoshuaBatty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
22 changes: 18 additions & 4 deletions
22
.../src/e2e_vm_tests/test_programs/should_fail/multiple_methods_with_the_same_name/test.toml
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,27 @@ | ||
category = "fail" | ||
|
||
# check: $()Type contains duplicate declarations | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()Duplicate definitions for the method "my_add" for type "Data<T>". | ||
# check: $()"my_add" previously defined here. | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()Method "my_add" already declared in type "Data<T>". | ||
|
||
# check: $()Type contains duplicate declarations | ||
# check: $()fn get_value(self) -> u64 { | ||
# check: $()"get_value" previously defined here. | ||
# check: $()fn get_value(self) -> u64 { | ||
# check: $()Duplicate definitions for the method "get_value" for type "Data<u64>". | ||
# check: $(Method "get_value" already declared in type "Data<u64>". | ||
|
||
# check: $()Type contains duplicate declarations | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()"my_add" previously defined here. | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()Duplicate definitions for the method "my_add" for type "Data<u64>". | ||
# check: $()Method "my_add" already declared in type "Data<u64>". | ||
|
||
# check: $()Type contains duplicate declarations | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()Duplicate definitions for the method "my_add" for type "Data<u32>". | ||
# check: $()"my_add" previously defined here. | ||
# check: $()fn my_add(self, other: Self) -> Self { | ||
# check: $()Method "my_add" already declared in type "Data<u64>". | ||
|
||
# check: $()Aborting due to 6 errors |
8 changes: 5 additions & 3 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/type_alias_shadowing_methods/test.toml
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
category = "fail" | ||
|
||
#check: $()impl Alias2 { | ||
#nextln: $()fn foo() {} | ||
#nextln: $()Duplicate definitions for the method "foo" for type "MyStruct1". | ||
#check: $()Type contains duplicate declarations | ||
#check: $()fn foo() {} | ||
#nextln: $()"foo" previously defined here. | ||
#check: $()fn foo() {} | ||
#nextln: $()Method "foo" already declared in type "Alias2" (which is an alias for "MyStruct1"). |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_fail/type_alias_unification/Forc.lock
This file contains hidden or 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-6E306998EEBF0DBD" | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-6E306998EEBF0DBD" | ||
dependencies = ["core"] | ||
|
||
[[package]] | ||
name = "type_alias_unification" | ||
source = "member" | ||
dependencies = ["std"] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/type_alias_unification/Forc.toml
This file contains hidden or 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 = "type_alias_unification" | ||
|
||
[dependencies] | ||
std = { path = "../../../reduced_std_libs/sway-lib-std-assert" } |
32 changes: 32 additions & 0 deletions
32
test/src/e2e_vm_tests/test_programs/should_fail/type_alias_unification/src/main.sw
This file contains hidden or 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,32 @@ | ||
script; | ||
|
||
trait MyTrait { | ||
fn extract_a(self) -> u64; | ||
} | ||
|
||
struct A { | ||
a: u64, | ||
} | ||
|
||
impl MyTrait for A { | ||
fn extract_a(self) -> u64 { | ||
self.a | ||
} | ||
} | ||
|
||
type B = A; | ||
|
||
// B is an alias for A, and A already has an implementation of MyTrait, | ||
// so this should cause a compilation error. | ||
impl MyTrait for B { | ||
fn extract_a(self) -> u64 { | ||
self.a + 1 | ||
} | ||
} | ||
|
||
fn main() { | ||
let struct_a = A { a: 1 }; | ||
let struct_b = B { a: 42 }; | ||
assert(struct_a.extract_a() == 1); | ||
assert(struct_b.extract_a() == 42); | ||
} |
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_fail/type_alias_unification/test.toml
This file contains hidden or 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 = "fail" | ||
|
||
#check: $()Trait is already implemented for type | ||
#check: $()This is the already existing implementation of "MyTrait" for "B" (which is an alias for "A"). | ||
#check: $()Trait "type_alias_unification::MyTrait" is already implemented for type "B" (which is an alias for "A"). | ||
|
||
#check: $()Aborting due to 1 error. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.