forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve parsing of trait constraints (FuelLabs#3143)
- Loading branch information
1 parent
d084bc1
commit 457beff
Showing
27 changed files
with
404 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
use crate::language::CallPath; | ||
use sway_types::Spanned; | ||
|
||
use crate::{language::CallPath, TypeArgument}; | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
pub(crate) struct TraitConstraint { | ||
pub(crate) call_path: CallPath, | ||
pub(crate) trait_name: CallPath, | ||
pub(crate) type_arguments: Vec<TypeArgument>, | ||
} | ||
|
||
impl Spanned for TraitConstraint { | ||
fn span(&self) -> sway_types::Span { | ||
self.trait_name.span() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_adts/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-9C8BB63A0EAABF66' | ||
|
||
[[package]] | ||
name = 'where_clause_adts' | ||
source = 'root' | ||
dependencies = ['core'] |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_adts/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[project] | ||
name = "where_clause_adts" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../sway-lib-core" } |
46 changes: 46 additions & 0 deletions
46
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_adts/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
script; | ||
|
||
trait MyAdd { | ||
fn my_add(a: Self, b: Self) -> Self; | ||
} | ||
|
||
struct MyU32 { | ||
value: u32 | ||
} | ||
|
||
struct MyU64 { | ||
value: u64 | ||
} | ||
|
||
impl MyAdd for MyU32 { | ||
fn my_add(a: MyU32, b: MyU32) -> MyU32 { | ||
MyU32 { | ||
value: a.value + b.value | ||
} | ||
} | ||
} | ||
|
||
impl MyAdd for MyU64 { | ||
fn my_add(a: MyU64, b: MyU64) -> MyU64 { | ||
MyU64 { | ||
value: a.value + b.value | ||
} | ||
} | ||
} | ||
|
||
struct MyPoint<T> where T: MyAdd { | ||
x: T, | ||
y: T, | ||
} | ||
|
||
fn main() -> u8 { | ||
let foo = MyPoint { | ||
x: 1u32, | ||
y: 2u64, | ||
}; | ||
let bar = MyPoint { | ||
x: 3u32, | ||
y: 4u64, | ||
}; | ||
0u8 | ||
} |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_adts/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
category = "fail" | ||
|
||
# check: $()struct MyPoint<T> where T: MyAdd { | ||
# nextln:$()"where" clauses are not yet supported | ||
|
||
# check: $()let foo = MyPoint { | ||
# nextln: $()Could not find symbol "MyPoint" in this scope. | ||
|
||
# check: $()MyPoint { | ||
# nextln: $()Unknown type name "MyPoint". | ||
|
||
# check: $()MyPoint { | ||
# nextln: $()Unknown type name "MyPoint". |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_functions/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-7DE2C09CF8DCCAB3' | ||
|
||
[[package]] | ||
name = 'where_clause_functions' | ||
source = 'root' | ||
dependencies = ['core'] |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_fail/where_clause_functions/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[project] | ||
name = "where_clause_functions" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../sway-lib-core" } |
Oops, something went wrong.