From 09ce196bf242eb3763e593e4b7838caee306d027 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 10 Nov 2025 12:03:17 -0300 Subject: [PATCH] fix: avoid producing duplicate private error messages --- compiler/noirc_frontend/src/elaborator/scope.rs | 6 ++++-- compiler/noirc_frontend/src/elaborator/types.rs | 8 +++++--- .../execute__tests__stderr.snap | 16 +--------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/compiler/noirc_frontend/src/elaborator/scope.rs b/compiler/noirc_frontend/src/elaborator/scope.rs index ee3e1841941..570f77255de 100644 --- a/compiler/noirc_frontend/src/elaborator/scope.rs +++ b/compiler/noirc_frontend/src/elaborator/scope.rs @@ -1,6 +1,7 @@ //! Lexical scoping, variable lookup, and closure capture tracking. use crate::ast::{ERROR_IDENT, Ident}; +use crate::elaborator::path_resolution::PathResolution; use crate::hir::def_map::{LocalModuleId, ModuleId}; use crate::hir::scope::{Scope as GenericScope, ScopeTree as GenericScopeTree}; @@ -226,8 +227,9 @@ impl Elaborator<'_> { path: TypedPath, mode: PathResolutionMode, ) -> Option> { - match self.resolve_path_or_error_inner(path, PathResolutionTarget::Type, mode) { - Ok(PathResolutionItem::TypeAlias(type_alias_id)) => { + match self.resolve_path_inner(path, PathResolutionTarget::Type, mode) { + Ok(PathResolution { item: PathResolutionItem::TypeAlias(type_alias_id), errors }) => { + self.push_errors(errors); Some(self.interner.get_type_alias(type_alias_id)) } _ => None, diff --git a/compiler/noirc_frontend/src/elaborator/types.rs b/compiler/noirc_frontend/src/elaborator/types.rs index fd0b5cca45a..e42737423da 100644 --- a/compiler/noirc_frontend/src/elaborator/types.rs +++ b/compiler/noirc_frontend/src/elaborator/types.rs @@ -13,7 +13,7 @@ use crate::{ AsTraitPath, BinaryOpKind, GenericTypeArgs, Ident, PathKind, UnaryOp, UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression, WILDCARD_TYPE, }, - elaborator::UnstableFeature, + elaborator::{UnstableFeature, path_resolution::PathResolution}, hir::{ def_collector::dc_crate::CompilationError, def_map::{ModuleDefId, fully_qualified_module_path}, @@ -619,8 +619,10 @@ impl Elaborator<'_> { } // If we cannot find a local generic of the same name, try to look up a global - match self.resolve_path_or_error_inner(path.clone(), PathResolutionTarget::Value, mode) { - Ok(PathResolutionItem::Global(id)) => { + match self.resolve_path_inner(path.clone(), PathResolutionTarget::Value, mode) { + Ok(PathResolution { item: PathResolutionItem::Global(id), errors }) => { + self.push_errors(errors); + if let Some(current_item) = self.current_item { self.interner.add_global_dependency(current_item, id); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_failure/orphaned_trait_impl/execute__tests__stderr.snap b/tooling/nargo_cli/tests/snapshots/compile_failure/orphaned_trait_impl/execute__tests__stderr.snap index 4eda3de99e9..f8e38245aa4 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_failure/orphaned_trait_impl/execute__tests__stderr.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_failure/orphaned_trait_impl/execute__tests__stderr.snap @@ -16,20 +16,6 @@ error: MyStruct is private and not visible from the current module │ -------- MyStruct is private │ -error: MyStruct is private and not visible from the current module - ┌─ src/main.nr:1:34 - │ -1 │ impl crate1::MyTrait for crate2::MyStruct { - │ -------- MyStruct is private - │ - -error: MyStruct is private and not visible from the current module - ┌─ src/main.nr:1:34 - │ -1 │ impl crate1::MyTrait for crate2::MyStruct { - │ -------- MyStruct is private - │ - error: Orphaned trait implementation ┌─ src/main.nr:1:26 │ @@ -37,4 +23,4 @@ error: Orphaned trait implementation │ ---------------- Either the type or the trait must be from the same crate as the trait implementation │ -Aborting due to 5 previous errors +Aborting due to 3 previous errors