-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…5722) # Description ## Problem Part of #5668 ## Summary ## Additional Context ## Documentation Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [x] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
6 changed files
with
115 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ mod module; | |
mod struct_def; | ||
mod trait_constraint; | ||
mod trait_def; | ||
mod trait_impl; | ||
mod typ; | ||
mod quoted; | ||
|
||
|
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,7 @@ | ||
impl TraitImpl { | ||
#[builtin(trait_impl_trait_generic_args)] | ||
fn trait_generic_args(self) -> [Type] {} | ||
|
||
#[builtin(trait_impl_methods)] | ||
fn methods(self) -> [FunctionDefinition] {} | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/comptime_trait_impl/Nargo.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,7 @@ | ||
[package] | ||
name = "comptime_trait_impl" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
32 changes: 32 additions & 0 deletions
32
test_programs/compile_success_empty/comptime_trait_impl/src/main.nr
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,32 @@ | ||
use std::meta::type_of; | ||
|
||
trait SomeTrait<X, Y> { | ||
fn foo(); | ||
} | ||
struct SomeStruct { | ||
|
||
} | ||
|
||
impl SomeTrait<i32, i64> for SomeStruct { | ||
fn foo() {} | ||
} | ||
|
||
fn main() { | ||
comptime | ||
{ | ||
let some_struct = quote { SomeStruct }.as_type(); | ||
let some_trait = quote { SomeTrait<i32, i64> }.as_trait_constraint(); | ||
let trait_impl = some_struct.get_trait_impl(some_trait).unwrap(); | ||
|
||
// Check TraitImpl::trait_generic_args | ||
let trait_generic_args = trait_impl.trait_generic_args(); | ||
assert_eq(trait_generic_args.len(), 2); | ||
assert_eq(trait_generic_args[0], quote { i32 }.as_type()); | ||
assert_eq(trait_generic_args[1], quote { i64 }.as_type()); | ||
|
||
// Check TraitImpl::methods | ||
let methods = trait_impl.methods(); | ||
assert_eq(methods.len(), 1); | ||
assert_eq(methods[0].name(), quote { foo }); | ||
} | ||
} |