diff --git a/compiler/noirc_frontend/src/elaborator/expressions.rs b/compiler/noirc_frontend/src/elaborator/expressions.rs index 6eed2c16e6b..1b7bc094058 100644 --- a/compiler/noirc_frontend/src/elaborator/expressions.rs +++ b/compiler/noirc_frontend/src/elaborator/expressions.rs @@ -750,19 +750,23 @@ impl<'context> Elaborator<'context> { &mut self, func: ExprId, location: Location, - ) -> Result { + ) -> Result, ResolverError> { match self.interner.expression(&func) { HirExpression::Ident(ident, _generics) => { - let definition = self.interner.definition(ident.id); - if let DefinitionKind::Function(function) = definition.kind { - let meta = self.interner.function_modifiers(&function); - if meta.is_comptime { - Ok(function) + if let Some(definition) = self.interner.try_definition(ident.id) { + if let DefinitionKind::Function(function) = definition.kind { + let meta = self.interner.function_modifiers(&function); + if meta.is_comptime { + Ok(Some(function)) + } else { + Err(ResolverError::MacroIsNotComptime { span: location.span }) + } } else { - Err(ResolverError::MacroIsNotComptime { span: location.span }) + Err(ResolverError::InvalidSyntaxInMacroCall { span: location.span }) } } else { - Err(ResolverError::InvalidSyntaxInMacroCall { span: location.span }) + // Assume a name resolution error has already been issued + Ok(None) } } _ => Err(ResolverError::InvalidSyntaxInMacroCall { span: location.span }), @@ -783,7 +787,7 @@ impl<'context> Elaborator<'context> { }); let function = match self.try_get_comptime_function(func, location) { - Ok(function) => function, + Ok(function) => function?, Err(error) => { self.push_err(error); return None;