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

Incorrect inference for default methods on generic traits #4099

Closed
brson opened this issue Dec 3, 2012 · 6 comments
Closed

Incorrect inference for default methods on generic traits #4099

brson opened this issue Dec 3, 2012 · 6 comments
Labels
A-traits Area: Trait system

Comments

@brson
Copy link
Contributor

brson commented Dec 3, 2012

trait A<T> {
    fn g(x: T) -> T { move x }
}

impl int: A<int> { }

fn main () {
    assert 0i.g(2i) == 2i;
}
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8:16: 8:18 error: mismatched types: expected `'a` but found `int` (expected type parameter but found int)
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8     assert 0i.g(2i) == 2i;
                                                                                              ^~
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8:11: 8:25 error: binary operation == cannot be applied to type `'a`
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8     assert 0i.g(2i) == 2i;
                                                                                         ^~~~~~~~~~~~~~
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8:11: 8:25 error: mismatched types: expected `bool` but found `'a` (expected bool but found type parameter)
/home/brian/dev/rust/src/test/run-pass/trait-default-method-bound-subst2.rs:8     assert 0i.g(2i) == 2i;
                                                                                         ^~~~~~~~~~~~~~
error: aborting due to 3 previous errors


@catamorphism
Copy link
Contributor

Reproduced as of eed2ca6

@ghost ghost assigned catamorphism Feb 21, 2013
@catamorphism
Copy link
Contributor

I noticed a comment in typeck::check::method::push_candidates_from_provided_methods that's just using an empty substitution all the time when checking default methods. This may be related; I annotated it with this issue number.

@msullivan
Copy link
Contributor

Updated version

#[allow(default_methods)];

trait A<T> {
    fn g(&self, x: T) -> T { x }
}

impl A<int> for int { }

fn main () {
    assert!(0i.g(2i) == 2i);
}

fails with an ICE in trans. Probably is the same bug as #4102.

@msullivan
Copy link
Contributor

push_candidates_from_provided_methods doesn't actually seem to get used... I am confused now.

@msullivan
Copy link
Contributor

Bug was in trans. push_candidates_from_provided_methods is (it appears) dead code. The code path that calls it never gets exercised, it seems?

@msullivan
Copy link
Contributor

Marking that this was part of #2794 for tracking purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system
Projects
None yet
Development

No branches or pull requests

3 participants