Skip to content
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
17 changes: 17 additions & 0 deletions compiler/noirc_frontend/src/parser/parser/type_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl Parser<'_> {
/// AtomTypeExpression
/// = ConstantTypeExpression
/// | VariableTypeExpression
/// | AsTraitPathTypeExpression
/// | ParenthesizedTypeExpression
fn parse_atom_type_expression(&mut self) -> Option<UnresolvedTypeExpression> {
if let Some(type_expr) = self.parse_constant_type_expression() {
Expand All @@ -153,6 +154,10 @@ impl Parser<'_> {
return Some(type_expr);
}

if let Some(as_trait_path) = self.parse_as_trait_path() {
return Some(UnresolvedTypeExpression::AsTraitPath(Box::new(as_trait_path)));
}

if let Some(type_expr) = self.parse_parenthesized_type_expression() {
return Some(type_expr);
}
Expand Down Expand Up @@ -474,6 +479,18 @@ mod tests {
assert_eq!(expr.to_string(), "(0 - N)");
}

#[test]
fn parses_as_trait_path_type_expression() {
let src = "<Type as Trait>::AssociatedType";
let typ = parse_type_expression_no_errors(src);
let UnresolvedTypeExpression::AsTraitPath(as_trait_path) = typ else {
panic!("Expected AsTraitPath");
};
assert_eq!(as_trait_path.typ.to_string(), "Type");
assert_eq!(as_trait_path.trait_path.to_string(), "Trait");
assert_eq!(as_trait_path.impl_item.to_string(), "AssociatedType");
}

#[test]
fn parse_type_or_type_expression_constant() {
let src = "42";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "as_trait_path_type_expression"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::mem::zeroed;

trait Trait {
let N: u32;
}

impl Trait for Field {
let N: u32 = 10;
}

fn main() {
let something: [Field; <Field as Trait>::N] = zeroed();
assert_eq(something.len(), <Field as Trait>::N);
}
16 changes: 1 addition & 15 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const TESTS_WITHOUT_STDOUT_CHECK: [&str; 0] = [];
/// These tests are ignored because of existing bugs in `nargo expand`.
/// As the bugs are fixed these tests should be removed from this list.
/// (some are ignored on purpose for the same reason as `IGNORED_NARGO_EXPAND_EXECUTION_TESTS`)
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 14] = [
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 8] = [
// bug
"associated_type_bounds",
// bug
Expand All @@ -189,25 +189,13 @@ const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 14] = [
// because it references another project by a relative path
"reexports",
// bug
"serialize_1",
// bug
"serialize_2",
// bug
"serialize_3",
// bug
"serialize_4",
// bug
"trait_function_calls",
// bug
"trait_method_mut_self",
// bug
"trait_static_methods",
// There's no "src/main.nr" here so it's trickier to make this work
"workspace_reexport_bug",
// bug
"type_trait_method_call_multiple_candidates",
// bug
"alias_trait_method_call_multiple_candidates",
];

/// These tests are ignored because of existing bugs in `nargo expand`.
Expand All @@ -223,8 +211,6 @@ const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 10] = [
"noirc_frontend_tests_traits_accesses_associated_type_inside_trait_impl_using_self",
"noirc_frontend_tests_traits_accesses_associated_type_inside_trait_using_self",
"noirc_frontend_tests_u32_globals_as_sizes_in_types",
// "noirc_frontend_tests_traits_as_trait_path_called_multiple_times_for_different_t_1",
// "noirc_frontend_tests_traits_as_trait_path_called_multiple_times_for_different_t_2",
];

const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_WITH_BUG_TESTS: [&str; 1] =
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading