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

Method not found depending on the order of impl traits. #5881

Open
esdrubal opened this issue Apr 19, 2024 · 0 comments
Open

Method not found depending on the order of impl traits. #5881

esdrubal opened this issue Apr 19, 2024 · 0 comments
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen

Comments

@esdrubal
Copy link
Contributor

esdrubal commented Apr 19, 2024

script;

struct SomeStruct<T> {
    cap: u64,
}

trait AbiEncode2 {
    fn abi_encode2(self, ref mut buffer: Buffer);
}

impl<T> AbiEncode2 for SomeStruct<T> where T: AbiEncode2
{
    fn abi_encode2(self, ref mut buffer: Buffer) {
        self.cap.abi_encode2(buffer);
    }
}

impl AbiEncode2 for u64
{
    fn abi_encode2(self, ref mut buffer: Buffer) { 
    }
}

fn main() {
}

Error:

14 |     fn abi_encode2(self, ref mut buffer: Buffer) {
15 |         self.cap.abi_encode2(buffer);
   |                  ^^^^^^^^^^^ No method named "abi_encode2" found for type "u64".
16 |     }

If I change the order to:

script;

struct SomeStruct<T> {
    cap: u64,
}

trait AbiEncode2 {
    fn abi_encode2(self, ref mut buffer: Buffer);
}

impl AbiEncode2 for u64
{
    fn abi_encode2(self, ref mut buffer: Buffer) { 
    }
}

impl<T> AbiEncode2 for SomeStruct<T> where T: AbiEncode2
{
    fn abi_encode2(self, ref mut buffer: Buffer) {
        self.cap.abi_encode2(buffer);
    }
}

fn main() {
}

It works

@esdrubal esdrubal added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Apr 19, 2024
@IGI-111 IGI-111 added the bug Something isn't working label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

No branches or pull requests

2 participants