Skip to content
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

Compiler panic when From is used #4901

Closed
LogvinovLeon opened this issue Apr 24, 2024 · 1 comment
Closed

Compiler panic when From is used #4901

LogvinovLeon opened this issue Apr 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@LogvinovLeon
Copy link
Contributor

Aim

I want to be able to use From/Into traits

Expected Behavior

They work

Bug

The application panicked (crashed).
Message: ICE: missing trait impl - should be caught during type checking
Location: compiler/noirc_frontend/src/monomorphization/mod.rs:994

To Reproduce

use dep::std::unsafe::zeroed;

pub fn resize<TItem, NEW_LEN, OLD_LEN>(src: [TItem; OLD_LEN]) -> [TItem; NEW_LEN] {
    assert(NEW_LEN >= OLD_LEN, "New length must be greater than or equal to old length");
    let mut dest = [zeroed(); NEW_LEN];
    for i in 0..OLD_LEN {
        dest[i] = src[i];
    }
    dest
}

struct Fragment<MAX_DATA_LEN> {
    data: [u8; MAX_DATA_LEN]
}

impl<DATA_LEN, MAX_DATA_LEN>  From<[u8; DATA_LEN]> for Fragment<MAX_DATA_LEN> {
    fn from(data: [u8; DATA_LEN]) -> Fragment<MAX_DATA_LEN> {
        Fragment { data: resize(data) }
    }
}


global MAX_PREFIXED_KEY_NIBBLE_LEN = 6;
global some_key: [u8; 2] = [0xab, 0xcd];
global some_key_fragment: Fragment<MAX_PREFIXED_KEY_NIBBLE_LEN> = From::from(some_key);

fn main() {
    println(some_key_fragment);
}

Project Impact

Nice-to-have

Impact Context

I can't use From/Into and am forced to write converter functions instead which is uglier

Workaround

Yes

Workaround Description

Convert using a function

Additional Context

No response

Installation Method

Binary (noirup default)

Nargo Version

0.26.0

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@LogvinovLeon LogvinovLeon added the bug Something isn't working label Apr 24, 2024
@asterite
Copy link
Collaborator

Fixed by #5602

Duplicate of #5602 and #5017

Please reopen if the code above still crashes on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants