-
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 unexpected trait dummy method error. (#5234)
## Description The unexpected trait dummy method error is now replaced by: `Trait "MyTrait" is not implemented for type "u64".` This is the intended behavior and now throws the equivalent of rust error. This commit also adds some improvements to the `DebugWithEngines`. Closes #5201 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Igor Rončević <[email protected]> Co-authored-by: IGI-111 <[email protected]>
- Loading branch information
1 parent
f979b18
commit aee7926
Showing
7 changed files
with
99 additions
and
2 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
3 changes: 3 additions & 0 deletions
3
.../src/e2e_vm_tests/test_programs/should_fail/trait_method_and_generic_trait_impl/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_and_generic_trait_impl" | ||
source = "member" |
6 changes: 6 additions & 0 deletions
6
.../src/e2e_vm_tests/test_programs/should_fail/trait_method_and_generic_trait_impl/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" | ||
license = "Apache-2.0" | ||
name = "trait_method_and_generic_trait_impl" | ||
implicit-std = false |
34 changes: 34 additions & 0 deletions
34
...rc/e2e_vm_tests/test_programs/should_fail/trait_method_and_generic_trait_impl/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,34 @@ | ||
script; | ||
|
||
struct MyStruct<T> { | ||
val: T | ||
} | ||
|
||
trait MyTrait { | ||
fn foo(self, other: Self) -> bool; | ||
} { | ||
fn bar(self, other: Self) -> bool { | ||
self.foo(other) | ||
} | ||
} | ||
|
||
impl <T> MyTrait for MyStruct<T> where T: MyTrait { | ||
fn foo(self, other: Self) -> bool { | ||
self.val.foo(other.val) | ||
} | ||
} | ||
|
||
fn main() -> bool { | ||
let my_struct_1 = MyStruct { val: 5 }; | ||
let my_struct_2 = MyStruct { val: 9 }; | ||
|
||
// Calling foo() gives us the following expected error: | ||
// Trait "MyTrait" is not implemented for type "u64". | ||
my_struct_1.foo(my_struct_2); | ||
|
||
// Calling bar() gives us the following expected error: | ||
// Trait "MyTrait" is not implemented for type "u64". | ||
my_struct_1.bar(my_struct_2); | ||
|
||
true | ||
} |
7 changes: 7 additions & 0 deletions
7
.../src/e2e_vm_tests/test_programs/should_fail/trait_method_and_generic_trait_impl/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,7 @@ | ||
category = "fail" | ||
|
||
# check: $()my_struct_1.foo(my_struct_2); | ||
# nextln: $()Trait "MyTrait" is not implemented for type "u64". | ||
|
||
# check: $()my_struct_1.bar(my_struct_2); | ||
# nextln: $()Trait "MyTrait" is not implemented for type "u64". |