-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
TypedExpr::get_type
(#5992)
# Description ## Problem Part of #5668 ## Summary ## Additional Context ## Documentation Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[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. --------- Co-authored-by: jfecher <[email protected]>
- Loading branch information
Showing
5 changed files
with
56 additions
and
2 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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
//! Contains methods on the built-in `TypedExpr` type for resolved and type-checked expressions. | ||
use crate::option::Option; | ||
|
||
impl TypedExpr { | ||
/// If this expression refers to a function definitions, returns it. Otherwise returns `Option::none()`. | ||
#[builtin(typed_expr_as_function_definition)] | ||
// docs:start:as_function_definition | ||
comptime fn as_function_definition(self) -> Option<FunctionDefinition> {} | ||
// docs:end:as_function_definition | ||
|
||
/// Returns the type of the expression, if the expression could be resolved without errors. | ||
#[builtin(typed_expr_get_type)] | ||
// docs:start:get_type | ||
comptime fn get_type(self) -> Option<Type> {} | ||
// docs:end:get_type | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/comptime_typed_expr/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_typed_expr" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/comptime_typed_expr/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,7 @@ | ||
fn main() { | ||
comptime | ||
{ | ||
let expr = quote { [1, 3] }.as_expr().unwrap().resolve(Option::none()); | ||
assert_eq(expr.get_type().unwrap(), quote { [Field; 2] }.as_type()); | ||
} | ||
} |