Skip to content

Type inferrence failure with methods and closures #2332

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

Closed
brson opened this issue May 2, 2012 · 1 comment
Closed

Type inferrence failure with methods and closures #2332

brson opened this issue May 2, 2012 · 1 comment

Comments

@brson
Copy link
Contributor

brson commented May 2, 2012

fn main() {
    chan_from_global_ptr() {|po|
        // The type of po looks inferrable but isn't
        po.send(true);
    };
}

type chan<T> = T;

impl chan<T: send> for chan<T> {

    fn send(+v: T) { fail }
}

fn chan_from_global_ptr<T: send>(
    f: fn~(chan<T>)
) {
}

/home/banderson/Dev/rust2/src/test/run-pass/test.rs:15:8: 15:15 error: the type of this value must be known in this context
/home/banderson/Dev/rust2/src/test/run-pass/test.rs:15         po.send(true);
@nikomatsakis
Copy link
Contributor

I think this inference failure is actually legitimate. The problem is the type declaration type chan<T> = T, which is pretty meaningless. So, in effect, you wind up with an expected type for the closure of fn~(T), which means that when we go to invoke the method, sure enough, we know nothing about what po is expected to be (it's T!).

If you change type chan<T> = T to enum chan<T> = uint or some such, it works fine.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
More robust comment parsing

fixes rust-lang#2170

I haven't ported the entire test suite yet. Once we've done that, I will remove the old parsing system (or in fact, turn them into errors so that accidental usage of old-style comments will be detected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants