Skip to content
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

Check for type aliases when implementing traits #6875

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "type_alias_unification"

[dependencies]
std = { path = "../../../reduced_std_libs/sway-lib-std-assert" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 };
// TODO: This results in disambiguation error, which is unhelpful since it doesn't get to the root of the problem - needs to recongnize that A == B

Check warning on line 30 in test/src/e2e_vm_tests/test_programs/should_fail/type_alias_unification/src/main.sw

View workflow job for this annotation

GitHub Actions / find-typos

"recongnize" should be "recognize".
assert(struct_a.extract_a() == 1);
assert(struct_b.extract_a() == 42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "fail"

#not: $()error
Loading