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

Adds test for implicit trait constraint. #6517

Merged
merged 5 commits into from
Sep 16, 2024
Merged
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,8 @@
[[package]]
name = "core"
source = "path+from-root-3F7C73944D096B89"

[[package]]
name = "implicit_trait_constraint"
source = "member"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
implicit-std = false
license = "Apache-2.0"
name = "implicit_trait_constraint"

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
script;
trait T2 {}
trait T1: T2 {
fn new() -> Self;
}

struct S {}
impl T2 for S {}
impl T1 for S {
fn new() -> Self {
S {}
}
}

fn bar<T>() -> T
where
T: T1,
{
T::new()
}

fn foo<T>() -> T
where
T: T2,
{
bar()
}

fn main() -> u64 {
let _:S = foo();
42
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()bar()
# nextln: $()Trait "T1" is not implemented for type "T".
Loading