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

Unexpected errors while using From trait returning tuples. #5299

Closed
esdrubal opened this issue Nov 23, 2023 · 0 comments · Fixed by #6590
Closed

Unexpected errors while using From trait returning tuples. #5299

esdrubal opened this issue Nov 23, 2023 · 0 comments · Fixed by #6590
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: high Should be looked at if there are no critical issues left

Comments

@esdrubal
Copy link
Contributor

script;

pub trait MyFrom<T> {
    fn from(b: T) -> Self;
}


pub trait MyInto<T> {
    fn into(self) -> T;
}


impl<T, U> MyInto<U> for T
where
    U: MyFrom<T>,
{
    fn into(self) -> U {
        U::from(self)
    }
}

impl MyFrom<u256> for (u64, u64, u64, u64) {
    fn from(val: u256) -> (u64, u64, u64, u64) {
        (0, 0, 0, 0)
    }
}

fn main() -> bool {
    let (_a, _b, _c, _d) = u256::min().into();

    true
}
error
            --> /home/marcos/Documents/dev/sway3/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw:67:40
             |
          65 | 
          66 | 
          67 |     let (_a, _b, _c, _d) = u256::min().into();
             |                                        ^^^^ Trait "MyFrom" is not implemented for type "U".
          68 | 
          69 |     true
             |
          ____

          error
            --> /home/marcos/Documents/dev/sway3/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw:32:9
             |
          30 | 
          31 | 
          32 | impl<T, U> MyInto<U> for T
             |         ^ Cannot infer type for type parameter "U". Insufficient type information provided. Try annotating its type.
          33 | where
          34 |     U: MyFrom<T>,
             |
          ____

          error
            --> /home/marcos/Documents/dev/sway3/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw:67:5
             |
          65 | 
          66 | 
          67 |     let (_a, _b, _c, _d) = u256::min().into();
             |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot infer type for type parameter "_". Insufficient type information provided. Try annotating its type.
          68 | 
          69 |     true
             |
          ____
@esdrubal esdrubal added bug Something isn't working P: high Should be looked at if there are no critical issues left compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Nov 23, 2023
@esdrubal esdrubal self-assigned this Nov 23, 2023
esdrubal added a commit that referenced this issue Sep 26, 2024
When we have a type annotation with placeholders and we assign to it the
result of a trait implementation call, if there is a single possible
trait implementation we can  use its type in the type annotation type.

Fixes #5299
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: high Should be looked at if there are no critical issues left
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant