diff --git a/crates/noirc_frontend/src/ast/structure.rs b/crates/noirc_frontend/src/ast/structure.rs index acfa8fa6e22..47dd432e739 100644 --- a/crates/noirc_frontend/src/ast/structure.rs +++ b/crates/noirc_frontend/src/ast/structure.rs @@ -8,7 +8,7 @@ use noirc_errors::Span; #[derive(Clone, Debug, PartialEq, Eq)] pub struct NoirStruct { pub name: Ident, - pub generics: Vec, + pub generics: UnresolvedGenerics, pub fields: Vec<(Ident, UnresolvedType)>, pub span: Span, } diff --git a/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs b/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs index 90ab9b21765..1c5dc4f178f 100644 --- a/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs +++ b/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs @@ -59,9 +59,9 @@ pub struct DefCollector { pub(crate) collected_impls: ImplMap, } -/// collected impls maps the type and the module id in which -/// the impl is defined to the functions contained in that impl -/// along with the generics declared on the impl itself. +/// Maps the type and the module id in which the impl is defined to the functions contained in that +/// impl along with the generics declared on the impl itself. This also contains the Span +/// of the object_type of the impl, used to issue an error if the object type fails to resolve. type ImplMap = HashMap<(UnresolvedType, LocalModuleId), Vec<(UnresolvedGenerics, Span, UnresolvedFunctions)>>; @@ -433,6 +433,9 @@ fn resolve_function_set( StandardPathResolver::new(ModuleId { local_id: mod_id, krate: crate_id }); let mut resolver = Resolver::new(interner, &path_resolver, def_maps, file_id); + // Must use set_generics here to ensure we re-use the same generics from when + // the impl was originally collected. Otherwise the function will be using different + // TypeVariables for the same generic, causing it to instantiate incorrectly. resolver.set_generics(impl_generics.clone()); resolver.set_self_type(self_type.clone()); diff --git a/crates/noirc_frontend/src/hir/resolution/resolver.rs b/crates/noirc_frontend/src/hir/resolution/resolver.rs index c238a964e01..fdcf2210148 100644 --- a/crates/noirc_frontend/src/hir/resolution/resolver.rs +++ b/crates/noirc_frontend/src/hir/resolution/resolver.rs @@ -861,7 +861,7 @@ impl<'a> Resolver<'a> { } Pattern::Struct(name, fields, span) => { let error_identifier = |this: &mut Self| { - // Must create a name here to return a HirPattern::Identifer. Allowing + // Must create a name here to return a HirPattern::Identifier. Allowing // shadowing here lets us avoid further errors if we define ERROR_IDENT // multiple times. let name = ERROR_IDENT.into();