Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tried to take element size of non-array type Field #2030

Closed
jfecher opened this issue Jul 25, 2023 · 1 comment · Fixed by #2217
Closed

Tried to take element size of non-array type Field #2030

jfecher opened this issue Jul 25, 2023 · 1 comment · Fixed by #2217
Assignees
Labels
bug Something isn't working ssa

Comments

@jfecher
Copy link
Contributor

jfecher commented Jul 25, 2023

Aim

Tried to run the following code:

fn main(x: bool) {
    let alloc = &mut 0;
    let mut array = [alloc];
    *array[0] = 2;
}

Expected Behavior

Expected the code to compile

Bug

Nargo panics with

The application panicked (crashed).
Message:  Uncaught type error: tried to take element size of non-array type Field
Location: crates/noirc_evaluator/src/ssa_refactor/ssa_gen/context.rs:589

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 13 frames hidden ⋮                              
  14: noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext::element_size::hbfbc6aa14f1205d4
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/context.rs:589
  15: noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext::assign_new_value::ha0e10abe0dabe327
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/context.rs:562
  16: noirc_evaluator::ssa_refactor::ssa_gen::<impl noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext>::codegen_assign::h586d83df2f6900cf
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:405
  17: noirc_evaluator::ssa_refactor::ssa_gen::<impl noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext>::codegen_expression::hc6ba5540ea9c2fa3
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:88
  18: noirc_evaluator::ssa_refactor::ssa_gen::<impl noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext>::codegen_block::h259d073623f1ca75
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:162
  19: noirc_evaluator::ssa_refactor::ssa_gen::<impl noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext>::codegen_expression::hc6ba5540ea9c2fa3
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:72
  20: noirc_evaluator::ssa_refactor::ssa_gen::<impl noirc_evaluator::ssa_refactor::ssa_gen::context::FunctionContext>::codegen_function_body::h9821399ac8bcac74
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:63
  21: noirc_evaluator::ssa_refactor::ssa_gen::generate_ssa::hd8d0bff39973686d
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs:44
  22: noirc_evaluator::ssa_refactor::optimize_into_acir::h12639e2bf02acae3
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor.rs:38
  23: noirc_evaluator::ssa_refactor::experimental_create_circuit::h0ba1f0deee1e6458
      at /.../noir/crates/noirc_evaluator/src/ssa_refactor.rs:80
  24: noirc_driver::compile_no_check::h533738fd7760537b
      at /.../noir/crates/noirc_driver/src/lib.rs:313
  25: noirc_driver::compile_main::h949a98290a2050f7
      at /.../noir/crates/noirc_driver/src/lib.rs:202
  26: nargo_cli::cli::compile_cmd::compile_circuit::hdea40452f16a43eb
      at /.../noir/crates/nargo_cli/src/cli/compile_cmd.rs:128
  27: nargo_cli::cli::prove_cmd::prove_with_path::h438ea682d49fe1d7
      at /.../noir/crates/nargo_cli/src/cli/prove_cmd.rs:112
  28: nargo_cli::cli::prove_cmd::run::hf530d941a1673c8b
      at /.../noir/crates/nargo_cli/src/cli/prove_cmd.rs:68
  29: nargo_cli::cli::start_cli::h43751d4bccc346c7
      at /.../noir/crates/nargo_cli/src/cli/mod.rs:80
  30: nargo::main::h6191217e448fb3f7
      at /.../noir/crates/nargo_cli/src/main.rs:14
  31: core::ops::function::FnOnce::call_once::ha1dae44d13ecbe00
      at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/function.rs:251
                                ⋮ 13 frames hidden ⋮                              
exit 101

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@jfecher jfecher added the bug Something isn't working label Jul 25, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 25, 2023
@jfecher jfecher self-assigned this Jul 25, 2023
@jfecher jfecher added the ssa label Jul 25, 2023
@jfecher
Copy link
Contributor Author

jfecher commented Jul 25, 2023

This is partly caused by *array[0] = 2; being parsed as (*array)[0] = 2 rather than *(array[0]) = 2;. Although I would think the type checker should flag a dereference of an array as invalid in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ssa
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants