From 7daee20a3c3628044e2e76b0a52abd5285a4432a Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Tue, 23 Jul 2024 15:37:48 -0300 Subject: [PATCH] fix: let std::unsafe::zeroed() work for slices (#5592) # Description ## Problem Resolves #5429 ## Summary An incorrect type literal type was being passed. ## Additional Context None. ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- compiler/noirc_frontend/src/monomorphization/mod.rs | 2 +- .../compile_success_empty/zeroed_slice/Nargo.toml | 7 +++++++ .../compile_success_empty/zeroed_slice/src/main.nr | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test_programs/compile_success_empty/zeroed_slice/Nargo.toml create mode 100644 test_programs/compile_success_empty/zeroed_slice/src/main.nr diff --git a/compiler/noirc_frontend/src/monomorphization/mod.rs b/compiler/noirc_frontend/src/monomorphization/mod.rs index a46f32e3094..c63a6961da5 100644 --- a/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -1595,7 +1595,7 @@ impl<'interner> Monomorphizer<'interner> { self.create_zeroed_function(parameter_types, ret_type, env, location) } ast::Type::Slice(element_type) => { - ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { + ast::Expression::Literal(ast::Literal::Slice(ast::ArrayLiteral { contents: vec![], typ: ast::Type::Slice(element_type.clone()), })) diff --git a/test_programs/compile_success_empty/zeroed_slice/Nargo.toml b/test_programs/compile_success_empty/zeroed_slice/Nargo.toml new file mode 100644 index 00000000000..650baead9e2 --- /dev/null +++ b/test_programs/compile_success_empty/zeroed_slice/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "zeroed_slice" +type = "bin" +authors = [""] +compiler_version = ">=0.31.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/zeroed_slice/src/main.nr b/test_programs/compile_success_empty/zeroed_slice/src/main.nr new file mode 100644 index 00000000000..44ccb2bd595 --- /dev/null +++ b/test_programs/compile_success_empty/zeroed_slice/src/main.nr @@ -0,0 +1,3 @@ +fn main() { + let _: [u8] = std::unsafe::zeroed(); +}