-
Notifications
You must be signed in to change notification settings - Fork 225
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
Trait specialization for array and slice leads to compilation error #3502
Comments
This is actually expected currently as a result of array literals being polymorphic over array or slice types. Fixing this would require a design change to separate "polymorphic over an array's size or a slice" from just "polymorphic over an array's size." Alternately since this feature is mostly unused by users we could remove it from the stdlib and duplicate the stdlib functions like |
Also, please note that traits are still experimental so expect some bugs 🙂 |
OK, then if it is documented, that would be preferred. It allows for considerable code reduction (duplicated definitions like your suggestion below).
Probably no, better avoid this. |
Aim
To implement a trait with dynamic behavior for an
array
type and aslice
typeExpected Behavior
Code should compile as is because the underlying types are supposed to be different.
NOTE
While this approach is nice because one can create an implementation for both types without duplicating the code, it is also inconsistent with other parts of the language. I cannot pass a slice to a method accepting an array, nor vice-versa (but it would be a great feature to have!!). In this issue's case however, it seemingly does indeed pass different instance types to "the same" (?!) method signature...
Bug
Error received on compilation:
Impl for type [u8] overlaps with existing impl
Linked issue: #3474
Tried a different approach:
This compiles, but echoes
array print
for both lines, which isn't expected.It should output
array print
, thenslice print
To Reproduce
Compile the examples above
Installation Method
Binary
Nargo Version
noirc version = 0.19.2+d7f919dcc001080ed24616ebbc37426ef7ac7638
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: