diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index 254e907fb0e..1be6207623a 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -216,6 +216,20 @@ impl<'a> FunctionContext<'a> { self.codegen_array_checked(elements, typ[1].clone())?; Tree::Branch(vec![slice_length.into(), slice_contents]) } + ast::Type::Array(len, _) => { + // A literal slice can be an array or a slice, + // however we convert the array into a slice because printable types + // do not handle slice array properly. + let slice_type = if let Type::Array(first_type, _) = &typ[0] { + Type::Slice(first_type.clone()) + } else { + typ[0].clone() + }; + let slice_length = self.builder.length_constant(len as u128); + + let slice_contents = self.codegen_array_checked(elements, slice_type)?; + Tree::Branch(vec![slice_length.into(), slice_contents]) + } _ => unreachable!("ICE: unexpected slice literal type, got {}", array.typ), }) } diff --git a/compiler/noirc_frontend/src/monomorphization/mod.rs b/compiler/noirc_frontend/src/monomorphization/mod.rs index 821ae7e7c4c..b6405c1d92b 100644 --- a/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -1309,7 +1309,7 @@ impl<'interner> Monomorphizer<'interner> { let typ = Type::Array(bytes_as_expr.len() as u32, Box::new(int_type)); let arr_literal = ArrayLiteral { typ, contents: bytes_as_expr }; - Expression::Literal(Literal::Array(arr_literal)) + Expression::Literal(Literal::Slice(arr_literal)) } fn queue_function( diff --git a/test_programs/execution_success/regression_5245/Nargo.toml b/test_programs/execution_success/regression_5245/Nargo.toml new file mode 100644 index 00000000000..8eccce02040 --- /dev/null +++ b/test_programs/execution_success/regression_5245/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_5245" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/regression_5245/Prover.toml b/test_programs/execution_success/regression_5245/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_programs/execution_success/regression_5245/src/main.nr b/test_programs/execution_success/regression_5245/src/main.nr new file mode 100644 index 00000000000..e9165144364 --- /dev/null +++ b/test_programs/execution_success/regression_5245/src/main.nr @@ -0,0 +1,6 @@ +use dep::std::field::modulus_be_bytes; + +fn main() -> pub [u8; 32] { + let bytes = dep::std::field::modulus_be_bytes(); + bytes.as_array() +}