-
Notifications
You must be signed in to change notification settings - Fork 219
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
Value used in lvalue array indexing does not have its type inferred #5606
Comments
This is from this chunk of code: https://github.com/noir-lang/noir/blob/master/compiler/noirc_frontend/src/elaborator/statements.rs#L322-L340 where we try to check the array or slice type instead of unifying. It is a bit awkward to fix since we want to allow arrays and slices so can't unify with either. We can fix it by using |
This issue is now a bit more severe since the LSP does infer the type from the return value, and shows the type hint. However the code fails to compile ( |
There's no way for us to infer a "array or slice type" any more so the best we could do here is infer an array type and require explicit annotations if a slice was desired instead. E.g. |
@nventuro ah, the Edit: Also, to elaborate why the LSP seemingly differs from the compiler, it actually doesn't, it's just that at the point of the for loop the compiler doesn't know the type yet. After |
Aim
Below is a simplified version of a real life function I wrote:
This fails to compile: it resports ambiguous expression errors, and complains about using bracket indexing for
concatenated
when its type is_
and notarray
. Typing the value withlet mut concatenated: [Field; 3] = std::unsafe::zeroed()
causes for the function to compile with no errors. I'm however surprised that I need to specify this type however, sinceconcatenated
is the return value of the function: I'd expect its type to be inferred automatically.This is of course not a huge issue, but I'm wondering whether this is a bug in the type inference mechanism, an oversight, or something that is not supported due to some implementation reason.
The text was updated successfully, but these errors were encountered: