From 8da40b75a36ebac51d5377311db3c55fa339dcac Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Tue, 5 Dec 2023 19:29:56 +0100 Subject: [PATCH] fix: initialise strings as u8 array (#3682) # Description ## Problem\* Resolves #3635 ## Summary\* String literals were initialised as field array instead of array of u8. ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** 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_evaluator/src/ssa/ssa_gen/mod.rs | 5 +++-- .../execution_success/regression_3635/Nargo.toml | 7 +++++++ .../execution_success/regression_3635/Prover.toml | 0 .../execution_success/regression_3635/src/main.nr | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test_programs/execution_success/regression_3635/Nargo.toml create mode 100644 test_programs/execution_success/regression_3635/Prover.toml create mode 100644 test_programs/execution_success/regression_3635/src/main.nr diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index acf60cd6799..41327c988d2 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -224,8 +224,9 @@ impl<'a> FunctionContext<'a> { } fn codegen_string(&mut self, string: &str) -> Values { - let elements = - vecmap(string.as_bytes(), |byte| self.builder.field_constant(*byte as u128).into()); + let elements = vecmap(string.as_bytes(), |byte| { + self.builder.numeric_constant(*byte as u128, Type::unsigned(8)).into() + }); let typ = Self::convert_non_tuple_type(&ast::Type::String(elements.len() as u64)); self.codegen_array(elements, typ) } diff --git a/test_programs/execution_success/regression_3635/Nargo.toml b/test_programs/execution_success/regression_3635/Nargo.toml new file mode 100644 index 00000000000..4f34121439e --- /dev/null +++ b/test_programs/execution_success/regression_3635/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_3635" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/regression_3635/Prover.toml b/test_programs/execution_success/regression_3635/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_programs/execution_success/regression_3635/src/main.nr b/test_programs/execution_success/regression_3635/src/main.nr new file mode 100644 index 00000000000..97a04f9d93f --- /dev/null +++ b/test_programs/execution_success/regression_3635/src/main.nr @@ -0,0 +1,8 @@ +use dep::std; + +fn main() { + let x: u8 = 0x61; + let y: u8 = "a".as_bytes()[0]; + assert_eq(x, y); + assert_eq(x >> 1, y >> 1); +}