From 0efcbad4f55f5a1a193dbd3e66561d2113464cb5 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Fri, 4 Aug 2023 12:08:24 -0500 Subject: [PATCH 1/2] Fix 2055 --- crates/noirc_evaluator/src/ssa/acir_gen/mod.rs | 2 +- crates/noirc_frontend/src/hir/resolution/resolver.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs index aca809a85fa..7409a199641 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -1121,7 +1121,7 @@ impl Context { #[cfg(test)] mod tests { - use std::{rc::Rc, collections::HashMap}; + use std::{collections::HashMap, rc::Rc}; use acvm::{ acir::{ 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); From 390c2f5603c18e7132b3cd6b7c12b4660357ec8a Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Mon, 7 Aug 2023 15:32:17 -0500 Subject: [PATCH 2/2] Add regression test --- .../tests/execution_success/generics/src/main.nr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 }