Skip to content

Commit

Permalink
fix: let std::unsafe::zeroed() work for slices (#5592)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
asterite authored Jul 23, 2024
1 parent 3aed671 commit 7daee20
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}))
Expand Down
7 changes: 7 additions & 0 deletions test_programs/compile_success_empty/zeroed_slice/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "zeroed_slice"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
3 changes: 3 additions & 0 deletions test_programs/compile_success_empty/zeroed_slice/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let _: [u8] = std::unsafe::zeroed();
}

0 comments on commit 7daee20

Please sign in to comment.