From 069ea27b7352d27796b03f17c17219b761020f78 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Fri, 21 Jul 2023 12:59:59 -0500 Subject: [PATCH] Allow shadowing by default --- .../src/hir/resolution/resolver.rs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/noirc_frontend/src/hir/resolution/resolver.rs b/crates/noirc_frontend/src/hir/resolution/resolver.rs index f314cd63e44..cb40ac32082 100644 --- a/crates/noirc_frontend/src/hir/resolution/resolver.rs +++ b/crates/noirc_frontend/src/hir/resolution/resolver.rs @@ -205,8 +205,6 @@ impl<'a> Resolver<'a> { warn_if_unused: bool, definition: DefinitionKind, ) -> HirIdent { - let allow_shadowing = allow_shadowing || &name == "_"; - if definition.is_global() { return self.add_global_variable_decl(name, definition); } @@ -952,7 +950,7 @@ impl<'a> Resolver<'a> { let decl = this.add_variable_decl( identifier, false, - false, + true, DefinitionKind::Local(None), ); (decl, this.resolve_expression(block)) @@ -1053,7 +1051,7 @@ impl<'a> Resolver<'a> { (Some(_), DefinitionKind::Local(_)) => DefinitionKind::Local(None), (_, other) => other, }; - let id = self.add_variable_decl(name, mutable.is_some(), false, definition); + let id = self.add_variable_decl(name, mutable.is_some(), true, definition); HirPattern::Identifier(id) } Pattern::Mutable(pattern, span) => { @@ -1535,6 +1533,25 @@ mod test { assert!(errors.is_empty()); } + #[test] + fn resolve_shadowing() { + let src = r#" + fn main(x : Field) { + let x = foo(x); + let x = x; + let (x, x) = (x, x); + let _ = x; + } + + fn foo(x : Field) -> Field { + x + } + "#; + + let errors = resolve_src_code(src, vec!["main", "foo"]); + assert!(errors.is_empty()); + } + fn path_unresolved_error(err: ResolverError, expected_unresolved_path: &str) { match err { ResolverError::PathResolutionError(PathResolutionError::Unresolved(name)) => {