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

Multiple trait constraints on the same function causing issues #3325

Closed
mohammadfawaz opened this issue Nov 8, 2022 · 1 comment · Fixed by #3631
Closed

Multiple trait constraints on the same function causing issues #3325

mohammadfawaz opened this issue Nov 8, 2022 · 1 comment · Fixed by #3631
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen P: critical Should be looked at before anything else

Comments

@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Nov 8, 2022

Code:

script;

use core::ops::*;

impl<T> Option<T> {
    pub fn ok_or<E>(self, err: E) -> Result<T, E> {
        match self {
            Option::Some(v) => Result::Ok(v),
            Option::None => Result::Err(err),
        }
    }
}

fn test_ok_or<T, E>(val: T, default: E) where T: Eq, E: Eq{
    match Option::Some(val).ok_or(default) {
        Result::Ok(inner) => assert(val == inner),
        Result::Err(_) => revert(0),
    }
}

fn main() {
    test_ok_or(true, 0);
}

The idea is that I want both T and E in test_ok_or to implement Eq so that I can add another test to compare errors. I currently get the following error:

error: Internal compiler error: Verification failed: Type mismatch found for call to 'eq_3'.
Please file an issue on the repository and include the code that triggered this error.

The error goes away where I remove the trait constraint E: Eq on test_ok_or.

@mohammadfawaz mohammadfawaz added bug Something isn't working P: critical Should be looked at before anything else compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Nov 8, 2022
@emilyaherbert emilyaherbert self-assigned this Nov 16, 2022
@emilyaherbert
Copy link
Contributor

Hi @mohammadfawaz, I wasn't able to replicate the failure, can you confirm? I have your example code in a PR here: #3631

otrho pushed a commit that referenced this issue Dec 17, 2022
I wasn't able to reproduce the error shown in #3325---I believe it to be
resolved in the form shown in #3325. This PR adds the code from that
issue to the test suite.

Closes #3325

Co-authored-by: emilyaherbert <[email protected]>
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 P: critical Should be looked at before anything else
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants