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

Expression type is ambiguous #4994

Open
LogvinovLeon opened this issue May 8, 2024 · 1 comment
Open

Expression type is ambiguous #4994

LogvinovLeon opened this issue May 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@LogvinovLeon
Copy link
Contributor

LogvinovLeon commented May 8, 2024

Aim

Getting this code to compile:

fn main() {
    let a: [u8; 10] = [1; 10];
    let b: [Field; 10] = a.map(|x| x as Field);
}

Expected Behavior

Compiles

Bug

Does not compile:

error: Expression type is ambiguous
  ┌─ /Users/leonidlogvinov/Dev/ZK/plain-repro/src/main.nr:3:36
  │
3 │     let b: [Field; 10] = a.map(|x| x as Field);
  │                                    ---------- Type must be known at this point
  │

Aborting due to 1 previous error

To Reproduce

  1. Try to compile

Project Impact

Nice-to-have

Impact Context

No response

Workaround

Yes

Workaround Description

I can write a loop instead, but it's uglier & more verbose. Ideally - would like to be able to cast whole arrays

Additional Context

No response

Installation Method

Binary (noirup default)

Nargo Version

nargo version = 0.28.0

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@TomAFrench
Copy link
Member

A type hint fixes this for now.

fn main() {
    let a: [u8; 10] = [1; 10];
    let b: [Field; 10] = a.map(|x: u8| x as Field);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants