Open nventuro opened 1 month ago
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 try_unify
to an array or slice first, then on failure trying to unify again to the other type and only then issuing an error if both fail.
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.