From f7fa69661006e1e10ddeecee1cdf8f024d6bc3e9 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 2 May 2024 23:34:28 +0100 Subject: [PATCH] fix: Use annotated type when checking declaration (#4966) # Description ## Problem\* Resolves https://github.com/noir-lang/noir/issues/4742 ## Summary\* ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- .../noirc_frontend/src/hir/type_check/stmt.rs | 4 +++- .../slice_init_with_complex_type/Nargo.toml | 7 +++++++ .../slice_init_with_complex_type/Prover.toml | 0 .../slice_init_with_complex_type/src/main.nr | 17 +++++++++++++++++ tooling/debugger/ignored-tests.txt | 3 ++- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test_programs/execution_success/slice_init_with_complex_type/Nargo.toml create mode 100644 test_programs/execution_success/slice_init_with_complex_type/Prover.toml create mode 100644 test_programs/execution_success/slice_init_with_complex_type/src/main.nr diff --git a/compiler/noirc_frontend/src/hir/type_check/stmt.rs b/compiler/noirc_frontend/src/hir/type_check/stmt.rs index f5f6e1e8180..0760749c9e0 100644 --- a/compiler/noirc_frontend/src/hir/type_check/stmt.rs +++ b/compiler/noirc_frontend/src/hir/type_check/stmt.rs @@ -348,8 +348,10 @@ impl<'interner> TypeChecker<'interner> { if annotated_type.is_unsigned() { self.lint_overflowing_uint(&rhs_expr, &annotated_type); } + annotated_type + } else { + expr_type } - expr_type } /// Check if an assignment is overflowing with respect to `annotated_type` diff --git a/test_programs/execution_success/slice_init_with_complex_type/Nargo.toml b/test_programs/execution_success/slice_init_with_complex_type/Nargo.toml new file mode 100644 index 00000000000..a372caf92e9 --- /dev/null +++ b/test_programs/execution_success/slice_init_with_complex_type/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "slice_init_with_complex_type" +type = "bin" +authors = [""] +compiler_version = ">=0.28.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/slice_init_with_complex_type/Prover.toml b/test_programs/execution_success/slice_init_with_complex_type/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_programs/execution_success/slice_init_with_complex_type/src/main.nr b/test_programs/execution_success/slice_init_with_complex_type/src/main.nr new file mode 100644 index 00000000000..01ccf2fdeff --- /dev/null +++ b/test_programs/execution_success/slice_init_with_complex_type/src/main.nr @@ -0,0 +1,17 @@ +struct strct1 { + elem1: Field, +} + +fn main() { + let var1: [[i32; 1]] = [[0]]; + let var2: [[i32; 1]] = var1; + + let var1: [(i32, u8)] = [(1, 2)]; + let var2: [(i32, u8)] = var1; + + let var3: [strct1] = [strct1 { elem1: 1321351 }]; + let var4: [strct1] = var3; + + let var1: [i32; 1] = [0]; + let var2: [[i32; 1]] = [var1]; +} diff --git a/tooling/debugger/ignored-tests.txt b/tooling/debugger/ignored-tests.txt index f2338e85bef..fccf4566258 100644 --- a/tooling/debugger/ignored-tests.txt +++ b/tooling/debugger/ignored-tests.txt @@ -22,4 +22,5 @@ no_predicates_numeric_generic_poseidon regression_4709 fold_distinct_return fold_fibonacci -fold_complex_outputs \ No newline at end of file +fold_complex_outputs +slice_init_with_complex_type \ No newline at end of file