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 type checking for trait inheritance #4213

Closed
brson opened this issue Dec 18, 2012 · 4 comments
Closed

Incorrect type checking for trait inheritance #4213

brson opened this issue Dec 18, 2012 · 4 comments
Labels
A-trait-system Area: Trait system

Comments

@brson
Copy link
Contributor

brson commented Dec 18, 2012

These all fail in slightly different ways:

pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub trait Angle<T>: Trig<T> {}

pub pure fn sin<A:Angle<R>, R>(theta: &A) -> R { theta.sin() }

fn foo<R, A:Angle<R>>(theta: A) -> R { sin(&theta) }

impl int: Trig<int> {
    pure fn sin(&self) -> int { 10 }
}

impl int: Angle<int> {
}

fn main() {
    assert foo(0) == 10;
}
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9:39: 9:42 error: mismatched types: expected `@Trig<'b>` but found `@Trig<'a>` (expected type parameter but found type parameter)
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9 fn foo<R, A:Angle<R>>(theta: A) -> R { sin(&theta) }
pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub trait Angle<T>: Trig<T> {}

pub pure fn sin<A:Angle<R>, R>(theta: &A) -> R { theta.sin() }

fn foo<A:Angle<R>, R>(theta: A) -> R { return sin(&theta); }

fn main() {
}
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9:46: 9:49 error: failed to find an implementation of trait @Angle<<V2>> for <V1>
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9 fn foo<A:Angle<R>, R>(theta: A) -> R { return sin(&theta); }
pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub trait Angle<T>: Trig<T> {}

pub pure fn sin<A:Angle<int>>(theta: &A) -> int { theta.sin() }

fn foo<A:Angle<int>>(theta: A) -> int { return sin(&theta); }

fn main() {
}
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9:47: 9:50 error: failed to find an implementation of trait @Angle<int> for <V1>
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9 fn foo<A:Angle<int>>(theta: A) -> int { return sin(&theta); }
pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub trait Angle<T>: Trig<T> {}

pub pure fn sin<A:Trig<R>, R>(theta: &A) -> R { theta.sin() }

fn foo<A:Angle<R>, R>(theta: A) -> R { sin(&theta) }

impl int: Trig<int> {
    pure fn sin(&self) -> int { 10 }
}

impl int: Angle<int> {
}

fn main() {
    assert foo(0) == 10;
}
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9:39: 9:52 error: mismatched types: expected `'b` but found `'a` (expected type parameter but found type parameter)
/home/brian/dev/rust/src/test/run-pass/trait-inheritance-typaram-order.rs:9 fn foo<A:Angle<R>, R>(theta: A) -> R { sin(&theta) }
@brson
Copy link
Contributor Author

brson commented Dec 18, 2012

The definition of sin is the only difference.

@brendanzab
Copy link
Member

@catamorphism

@ghost ghost assigned catamorphism Jan 24, 2013
@catamorphism
Copy link
Contributor

Yet another one I didn't get to for 0.6. De-milestoning

@graydon
Copy link
Contributor

graydon commented May 8, 2013

All these examples (updated for current code) work now. Closing.

@graydon graydon closed this as completed May 8, 2013
RalfJung added a commit to RalfJung/rust that referenced this issue Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

4 participants