diff --git a/crates/nargo_cli/tests/execution_success/generics/src/main.nr b/crates/nargo_cli/tests/execution_success/generics/src/main.nr index bfde9d3c957..4c87bc685f1 100644 --- a/crates/nargo_cli/tests/execution_success/generics/src/main.nr +++ b/crates/nargo_cli/tests/execution_success/generics/src/main.nr @@ -54,4 +54,18 @@ fn main(x: Field, y: Field) { let two = y; let nested_generics: Bar> = Bar { one, two, other: Bar { one, two, other: 0 } }; assert(nested_generics.other.other == bar1.get_other()); + + let _ = regression_2055([1, 2, 3]); +} + +fn regression_2055(bytes: [u8; LEN]) -> Field { + let mut f = 0; + let mut b = 1; + let mut len = LEN - 1; // FAILS + for i in 0..LEN { + let j = len - i; + f += (bytes[j] as Field) * b; + b *= 256; + } + f } diff --git a/crates/noirc_frontend/src/hir/resolution/resolver.rs b/crates/noirc_frontend/src/hir/resolution/resolver.rs index 681c853899f..45ff21e3001 100644 --- a/crates/noirc_frontend/src/hir/resolution/resolver.rs +++ b/crates/noirc_frontend/src/hir/resolution/resolver.rs @@ -1008,7 +1008,16 @@ impl<'a> Resolver<'a> { match self.interner.definition(hir_ident.id).kind { DefinitionKind::Function(_) => {} DefinitionKind::Global(_) => {} - DefinitionKind::GenericType(_) => {} + DefinitionKind::GenericType(_) => { + // Initialize numeric generics to a polymorphic integer type in case + // they're used in expressions. We must do this here since the type + // checker does not check definition kinds and otherwise expects + // parameters to already be typed. + if self.interner.id_type(hir_ident.id) == Type::Error { + let typ = Type::polymorphic_integer(self.interner); + self.interner.push_definition_type(hir_ident.id, typ); + } + } // We ignore the above definition kinds because only local variables can be captured by closures. DefinitionKind::Local(_) => { self.resolve_local_variable(hir_ident, var_scope_index);