Skip to content

Commit 41f31d3

Browse files
Fixes compiler asking for unnecessary disambiguation for trait methods. (#5801)
## Description `find_method_for_type` was throwing an error when multiple implementations of a method exist receiving different kinds of unsigned int. This was caused by the coercion comparison which returned true while comparing any uint size to any other uint size. The solution was to change the UnifyCheck on Coercion to only return true to same size uints. Fixes #5798 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [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: Joshua Batty <joshpbatty@gmail.com>
1 parent efe725e commit 41f31d3

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

sway-core/src/type_system/unify/unify_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<'a> UnifyCheck<'a> {
375375
(Unknown, _) => true,
376376
(_, Unknown) => true,
377377

378-
(UnsignedInteger(_), UnsignedInteger(_)) => true,
378+
(UnsignedInteger(lb), UnsignedInteger(rb)) => lb == rb,
379379
(Numeric, UnsignedInteger(_)) => true,
380380
(UnsignedInteger(_), Numeric) => true,
381381

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[package]]
2+
name = "core"
3+
source = "path+from-root-13393DAFAC4DB2CA"
4+
5+
[[package]]
6+
name = "method_unambiguous"
7+
source = "member"
8+
dependencies = ["std"]
9+
10+
[[package]]
11+
name = "std"
12+
source = "path+from-root-13393DAFAC4DB2CA"
13+
dependencies = ["core"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
entry = "main.sw"
4+
license = "Apache-2.0"
5+
name = "method_unambiguous"
6+
7+
[dependencies]
8+
std = { path = "../../../../../../../sway-lib-std" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
script;
2+
3+
use std::convert::From;
4+
5+
impl From<u8> for u256 {
6+
fn from(num: u8) -> Self {
7+
num.as_u256()
8+
}
9+
}
10+
11+
impl From<u16> for u256 {
12+
fn from(num: u16) -> Self {
13+
num.as_u256()
14+
}
15+
}
16+
17+
fn main() -> u64 {
18+
use std::assert::assert;
19+
20+
let u256_value = u256::from(255_u8);
21+
assert(u256_value == 0x00000000000000000000000000000000000000000000000000000000000000ff_u256);
22+
23+
let u256_value = u256::from(65535_u16);
24+
assert(u256_value == 0x000000000000000000000000000000000000000000000000000000000000ffff_u256);
25+
26+
1
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
category = "run"
2+
expected_result = { action = "return", value = 1 }
3+
validate_abi = false

0 commit comments

Comments
 (0)