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

Calling default methods on type parameters that are type parameterized traits does not work #4102

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

Comments

@brson
Copy link
Contributor

brson commented Dec 3, 2012

Up-to-date (forward-ported) test case

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

impl A<int> for int { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(j)
}

fn main () {
    fail_unless!(f(0, 2) == 2);
}

Original Report

This assumes #4101 is merged. Fails in trans because substs for the parameterized trait A are not handled correctly.

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

impl int: A<int> { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(move j)
}

fn main () {
    assert f(0, 2) == 2;
}
@catamorphism
Copy link
Contributor

Reproduced as of eed2ca6

@pnkfelix
Copy link
Member

Reproduced as of c202430

@pnkfelix
Copy link
Member

Not critical for 0.6; de-milestoning

@catamorphism
Copy link
Contributor

Nominating for milestone 5, production-ready

@msullivan
Copy link
Contributor

Fails in typecheck now...

@msullivan
Copy link
Contributor

Oh, wait, that is because implicit self is gone. It still fails in trans.

#[allow(default_methods)];

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

impl A<int> for int { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(j)
}

fn main () {
    assert!(f(0, 2) == 2);
}

is an updated version

@msullivan
Copy link
Contributor

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

@msullivan
Copy link
Contributor

I claimed that I fixed this in an earlier commit, but I found another case that could cause a similar failure. Will be pushing a fix soon.

bors added a commit that referenced this issue Jun 21, 2013
This fixes the large number of problems that prevented cross crate
methods from ever working. It also fixes a couple lingering bugs with
polymorphic default methods and cleans up some of the code paths.

Closes #4102. Closes #4103.

r? nikomatsakis
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

Successfully merging a pull request may close this issue.

4 participants