diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index c4a300e032a..7cb055cfa06 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -143,14 +143,12 @@ 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; 15] = [ +const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 14] = [ // There's no "src/main.nr" here so it's trickier to make this work "overlapping_dep_and_mod", // bug "reexports", // bug - "regression_4436", - // bug "regression_7038", // bug "regression_7038_2", diff --git a/tooling/nargo_cli/src/cli/expand_cmd/printer/hir.rs b/tooling/nargo_cli/src/cli/expand_cmd/printer/hir.rs index 5bac2653a74..f1c51a634b0 100644 --- a/tooling/nargo_cli/src/cli/expand_cmd/printer/hir.rs +++ b/tooling/nargo_cli/src/cli/expand_cmd/printer/hir.rs @@ -694,8 +694,19 @@ impl ItemPrinter<'_, '_, '_> { let definition = self.interner.definition(ident.id); match definition.kind { DefinitionKind::Function(func_id) => { - let use_import = true; - self.show_reference_to_module_def_id(ModuleDefId::FunctionId(func_id), use_import); + let func_meta = self.interner.function_meta(&func_id); + if func_meta.self_type.is_some() && func_meta.self_type == self.self_type { + // No need to fully-qualify the function name if its self type is the current self type + let name = self.interner.function_name(&func_id); + self.push_str("Self::"); + self.push_str(name); + } else { + let use_import = true; + self.show_reference_to_module_def_id( + ModuleDefId::FunctionId(func_id), + use_import, + ); + } } DefinitionKind::Global(global_id) => { let global_info = self.interner.get_global(global_id); diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4436/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4436/execute__tests__expanded.snap new file mode 100644 index 00000000000..52f9123d9a0 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4436/execute__tests__expanded.snap @@ -0,0 +1,39 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait LibTrait { + fn broadcast(); + + fn get_constant() -> Field; +} + +pub global STRUCT_A_LEN: u32 = 3; + +pub global STRUCT_B_LEN: u32 = 5; + +pub struct StructA {} + +impl LibTrait for StructA { + fn broadcast() { + let _: Field = Self::get_constant(); + } + + fn get_constant() -> Field { + 1 + } +} + +pub struct StructB {} + +impl LibTrait for StructB { + fn broadcast() { + let _: Field = Self::get_constant(); + } + + fn get_constant() -> Field { + 1 + } +} + +fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4635/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4635/execute__tests__expanded.snap index 5f42ed09136..0e4a531724a 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4635/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_empty/regression_4635/execute__tests__expanded.snap @@ -30,7 +30,7 @@ impl FromField for AztecAddress { impl Deserialize<1> for AztecAddress { fn deserialize(fields: [Field; 1]) -> Self { - FromField::from_field(fields[0]) + Self::from_field(fields[0]) } } diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_1/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_1/execute__tests__expanded.snap index 904573033b7..312d9347639 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_1/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_1/execute__tests__expanded.snap @@ -12,7 +12,7 @@ pub struct Foo {} impl MagicNumber for Foo { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { @@ -24,7 +24,7 @@ pub struct Bar {} impl MagicNumber for Bar { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_2/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_2/execute__tests__expanded.snap index b83cf75f0cf..08d1991a58e 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_2/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_2/execute__tests__expanded.snap @@ -14,7 +14,7 @@ pub struct Foo {} impl MagicNumber for Foo { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { @@ -26,7 +26,7 @@ pub struct Bar {} impl MagicNumber for Bar { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_3/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_3/execute__tests__expanded.snap index f301a33e09a..998dc54625c 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_3/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_traits_returns_self_in_trait_method_3/execute__tests__expanded.snap @@ -12,7 +12,7 @@ pub trait MagicNumber { impl MagicNumber for i32 { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { @@ -22,7 +22,7 @@ impl MagicNumber for i32 { impl MagicNumber for i64 { fn from_magic_value() -> Self { - MagicNumber::from_value() + Self::from_value() } fn from_value() -> Self { diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_for_struct_function_call/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_for_struct_function_call/execute__tests__expanded.snap index a9ffaaeca8a..fa789b2761f 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_for_struct_function_call/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_for_struct_function_call/execute__tests__expanded.snap @@ -10,7 +10,7 @@ impl S { } fn two() -> Field { - S::one() + S::one() + Self::one() + Self::one() } } diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap index 03aa7f7d8f1..c38a4aa16cf 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap @@ -12,7 +12,7 @@ trait Foo { impl Foo for Field { fn foo() -> Self { - Foo::bar() + Self::bar() } fn bar() -> Self { diff --git a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_visibility_does_not_error_if_calling_private_struct_function_from_same_struct/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_visibility_does_not_error_if_calling_private_struct_function_from_same_struct/execute__tests__expanded.snap index 4e85a83a92c..82948a9de78 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_visibility_does_not_error_if_calling_private_struct_function_from_same_struct/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/compile_success_no_bug/noirc_frontend_tests_visibility_does_not_error_if_calling_private_struct_function_from_same_struct/execute__tests__expanded.snap @@ -6,7 +6,7 @@ struct Foo {} impl Foo { fn foo() { - Foo::bar() + Self::bar() } fn bar() {} diff --git a/tooling/nargo_cli/tests/snapshots/expand/execution_success/binary_operator_overloading/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/execution_success/binary_operator_overloading/execute__tests__expanded.snap index edba8f2600a..6333c1e579b 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/execution_success/binary_operator_overloading/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/execution_success/binary_operator_overloading/execute__tests__expanded.snap @@ -50,61 +50,61 @@ impl Wrapper { impl Add for Wrapper { fn add(self, other: Self) -> Self { - Wrapper::new(self.inner + other.inner) + Self::new(self.inner + other.inner) } } impl Sub for Wrapper { fn sub(self, other: Self) -> Self { - Wrapper::new(self.inner - other.inner) + Self::new(self.inner - other.inner) } } impl Mul for Wrapper { fn mul(self, other: Self) -> Self { - Wrapper::new(self.inner * other.inner) + Self::new(self.inner * other.inner) } } impl Div for Wrapper { fn div(self, other: Self) -> Self { - Wrapper::new(self.inner / other.inner) + Self::new(self.inner / other.inner) } } impl Rem for Wrapper { fn rem(self, other: Self) -> Self { - Wrapper::new(self.inner % other.inner) + Self::new(self.inner % other.inner) } } impl BitAnd for Wrapper { fn bitand(self, other: Self) -> Self { - Wrapper::new(self.inner & other.inner) + Self::new(self.inner & other.inner) } } impl BitOr for Wrapper { fn bitor(self, other: Self) -> Self { - Wrapper::new(self.inner | other.inner) + Self::new(self.inner | other.inner) } } impl BitXor for Wrapper { fn bitxor(self, other: Self) -> Self { - Wrapper::new(self.inner ^ other.inner) + Self::new(self.inner ^ other.inner) } } impl Shl for Wrapper { fn shl(self, other: u8) -> Self { - Wrapper::new(self.inner << other) + Self::new(self.inner << other) } } impl Shr for Wrapper { fn shr(self, other: u8) -> Self { - Wrapper::new(self.inner >> other) + Self::new(self.inner >> other) } } diff --git a/tooling/nargo_cli/tests/snapshots/expand/execution_success/unary_operator_overloading/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/expand/execution_success/unary_operator_overloading/execute__tests__expanded.snap index 9b3b6fa4210..aeb331b23bf 100644 --- a/tooling/nargo_cli/tests/snapshots/expand/execution_success/unary_operator_overloading/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/expand/execution_success/unary_operator_overloading/execute__tests__expanded.snap @@ -25,12 +25,12 @@ impl Wrapper { impl Neg for Wrapper { fn neg(self) -> Self { - Wrapper::new(-self.inner) + Self::new(-self.inner) } } impl Not for Wrapper { fn not(self) -> Self { - Wrapper::new(!self.inner) + Self::new(!self.inner) } }