-
Notifications
You must be signed in to change notification settings - Fork 248
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
Inferred array lengths on function returns do not work when defined in the wrong order #562
Comments
Since we have already a PR to handle slices, the best would be to not try to infer slice length in the frontend and uses PR #314 which uses proper function ordering for getting the length. |
After the last internal discussion, it seems we were leaning more towards option 1, requiring users to be explicit instead. It seems option 1 requires changing some name resolution items so that the N generic can be in scope in an expression position of the array types. So perhaps option 2 may actually be less code changes required overall. |
I forgot about the slice PR, until we reviewed the PRs recently, this is why I did not mention it when we discussed this issue. |
My main concern is that they interlap, there is no real reason to support both. |
does not rust have both? |
It does, but that is because slices are semantically different from arrays in rust in terms of runtime semantics. Namely in whether they're passed by value copying the whole array or passed by reference and carrying the length of the array as a separate field. This is not true for noir so we should not support both. |
Closing this. The old sugared generics syntax has finally been removed and the syntax now stands for slices which cause the example to work as-is. |
Description
Aim
Trying to use inferred array lengths on a function's return type:
Expected behavior
The program to work without issue.
Bug
The compiler is unable to infer the correct array size for
a
leading to an internal compiler panic during monomorphisation. This is because to see that the length of the returned array should be equal to the input array, it would need to inferfoo
beforemain
, but it instead starts inferring the type ofmain
first.Possible fixes
The text was updated successfully, but these errors were encountered: