Skip to content

Commit

Permalink
Test dot method calls disambiguation with self (FuelLabs#4649)
Browse files Browse the repository at this point in the history
related to issues FuelLabs#4383 and FuelLabs#4563

## Description


## 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: IGI-111 <[email protected]>
  • Loading branch information
anton-trunov and IGI-111 authored Jun 13, 2023
1 parent 52ac9b6 commit 6a4b6c0
Showing 1 changed file with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait MySuperTrait {
fn method() -> u64;
}

trait MyTrait : MySuperTrait {
trait MyTrait: MySuperTrait {
fn method() -> u64;
}

Expand All @@ -28,10 +28,45 @@ impl MyTrait for S {
}
}

// same test case but the methods take `self` as a parameter
struct T {}

impl T {
fn method_self(self) -> u64 {
1
}
}

trait MySuperTraitSelf {
fn method_self(self) -> u64;
}

trait MyTraitSelf: MySuperTraitSelf {
fn method_self(self) -> u64;
}

impl MySuperTraitSelf for T {
fn method_self(self) -> u64 {
2
}
}

impl MyTraitSelf for T {
fn method_self(self) -> u64 {
3
}
}

fn main() -> bool {
assert(S::method() == 1);
assert(<S as MySuperTrait>::method() == 2);
assert(<S as MyTrait>::method() == 3);

true
}
let t = T {};
// t.method_self() disambiguates to T::method_self
assert(t.method_self() == T::method_self(t));
assert(<T as MySuperTraitSelf>::method_self(t) == 2);
assert(<T as MyTraitSelf>::method_self(t) == 3);

true
}

0 comments on commit 6a4b6c0

Please sign in to comment.