Skip to content

Commit

Permalink
Adds test for implicit trait constraint. (#6517)
Browse files Browse the repository at this point in the history
## Description

This PR adds a test that proves implicit trait constraint already
returns
 an error. The method dummy ICE reported in #6377 was fixed by #6490.

Closes #6377.

## 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: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent ba153b2 commit ea4b9e9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
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".

0 comments on commit ea4b9e9

Please sign in to comment.