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

Block type-inference sometimes fails #912

Closed
marijnh opened this issue Sep 13, 2011 · 7 comments
Closed

Block type-inference sometimes fails #912

marijnh opened this issue Sep 13, 2011 · 7 comments
Labels
A-typesystem Area: The type system E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@marijnh
Copy link
Contributor

marijnh commented Sep 13, 2011

The follow code fails with

foo.rs:5:14: 5:18 error: the type of this value must be known in this context
foo.rs:5     find({|f| f.id == x}, arr);
                       ^~~~

If I move the += statement above the call to find, it typechecks. Maybe this is a fundamental limitation of our typechecker, but it looks like it could be worked around by delaying the error until all constraints in a function have been collected.

fn find<@T>(_f: block(T) -> bool, _v: [T]) {}

fn main() {
    let x = 10, arr = [];
    find({|f| f.id == x}, arr);
    arr += [{id: 20}]; // This assigns a type to arr
}
@msullivan
Copy link
Contributor

The problem is that in order to typecheck the block, we need to figure out what f is. We currently use the hack of checking all of the none block arguments in a function call before checking the block arguments. I spent some time looking into this.

The way that MLton deals with the similar problem in inferring functions that use SML flex-records is that it gives f a flexible record type that tracks the fields you know to be in the record. And then I think when it comes time to generalize the type variable, you require that the flex record be fully resolved (which would happen by unifying it with a non-flex record type). Unfortunately, autoderef screws that up some...

@brson
Copy link
Contributor

brson commented Mar 6, 2012

Still doesn't work.

@ghost ghost assigned pcwalton Mar 15, 2012
@catamorphism
Copy link
Contributor

Still a bug, 6/21/2012.

@catamorphism
Copy link
Contributor

Still a bug, 7/26/2012.

@msullivan
Copy link
Contributor

Is this something we intend to fix?

@msullivan
Copy link
Contributor

Because I think really fixing it requires getting rid of all of the places where we demand to know the type (or the first level of the type) of something.

@nikomatsakis
Copy link
Contributor

I don't believe this issue will ever be fixed. This amounts to restructuring the inference to have much more complex constraints like "a type that auto-derefs to something with a field f" and so forth. It would be more-or-less equivalent, I guess, to defering analysis of any particular expression when insufficient information is available and then re-checking until we reach a fixed point. Of course you wouldn't implement it like that, but whatever you did it would not be H-M nor even, really, inspired by H-M. I'm just going to close.

astrieanna added a commit to astrieanna/rust that referenced this issue Nov 11, 2013
This was marked xfail-test
According to rust's issue rust-lang#912, this will not be fixed.
There's no point in keeping the test if it is never intended to pass.
bors added a commit that referenced this issue Nov 12, 2013
According to rust's issue #912, this will not be fixed. There's no point in keeping the test if it is never intended to pass.
bors pushed a commit to rust-lang-ci/rust that referenced this issue Oct 26, 2020
Bumps [quote](https://github.com/dtolnay/quote) from 1.0.2 to 1.0.3.
- [Release notes](https://github.com/dtolnay/quote/releases)
- [Commits](dtolnay/quote@1.0.2...1.0.3)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
coastalwhite pushed a commit to coastalwhite/rust that referenced this issue Aug 5, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

6 participants