-
Notifications
You must be signed in to change notification settings - Fork 200
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
for-each sugar does not work in the standard library. #618
Comments
Number 2 seems to be a new feature that is not in the rust language. We should investigate the available options here and how it's done in Rust. IIUC 'crate' cannot be used in this case because the for-each sugar can be in any module. 'std' seems like it's not exactly right because now a language feature depends on the stdlib, whereas we can compile Noir code without it in the web. |
May be we should have an internal crate which is part of noir and includes functions used by the language itself such as the array length. |
Rust allows crates to refer to themselves via their own name if there is a lib.rs file present alongside or instead of main.rs. I see no reason why we couldn't always allow this by default. I wasn't aware of compiling noir code without the standard lib (why not include it anyway?) - but even if one wanted to not include the stdlib I think builtins like |
When there is a main.rs alongside a lib.rs, the main.rs file can call the lib.rs but these are seen as two different crates. So main.rs won't be able to access anything that has pub(crate) visibility in lib.rs for example.
You can do this in typescript but I think it worth bringing this up in our next meeting to see if we can enforce this
I agree and maybe we will need to always include stdlib or maybe have a |
@jfecher whats the status of this issue? |
This was fixed when the desugaring was changed from |
Description
Aim
Using a for-each loop in a std lib file such as
hash.nr
:Expected behavior
It to loop over each element of the array.
Bug
Instead the compiler crashes claiming it cannot find the
std
module. This is likely due to the above loop desugaring into:and the standard library expects the len function to be referred to as
crate::array::len
rather thanstd::array::len
.There are two items that should be fixed here
crate
. This enables us to have a non-relative module hierarchy where we do not need to change name references based on which module they are used in.The text was updated successfully, but these errors were encountered: