Skip to content

Typechecker should stop this #802

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
eholk opened this issue Aug 4, 2011 · 6 comments
Closed

Typechecker should stop this #802

eholk opened this issue Aug 4, 2011 · 6 comments
Labels
A-type-system Area: Type system

Comments

@eholk
Copy link
Contributor

eholk commented Aug 4, 2011

tag foo = int;

fn main() {
   let x = foo(1);
   if x == -1 { }
}

This program should not compile, but it does.

@msullivan
Copy link
Contributor

That seems legitimate. We do autoderef on binary operators.

@eholk
Copy link
Contributor Author

eholk commented Aug 5, 2011

I guess maybe the real solution is that we need proper abstract types. Still, I question whether autoderefing tags makes sense. Tags seem very different from pointers.

@marijnh
Copy link
Contributor

marijnh commented Aug 11, 2011

Autoderef on newtype-tags is important in at least one case: Using such a type to break a recursive type. You'll wrap your record in a newtype in such a case, and it is hugely convenient to be able to do val.field instead of (*val).field on wrapped values.

Maybe we should just stop autodereferencing for binary ops? That's not a feature I would expect.

@eholk
Copy link
Contributor Author

eholk commented Aug 11, 2011

I think removing autoderef for binary ops is a good idea. As Sully was pointing out earlier today, it limits our ability to do type-inference for binary operations.

@pcwalton
Copy link
Contributor

As written, this works as intended. I'd personally be in favor of removing autoderef too, but IMHO it should be a separate bug.

@kevina
Copy link
Contributor

kevina commented Feb 6, 2012

I personally think that for true pointer types Rust should auto-deference more. In 99.99% of the cases I do not care if something is a pointer or an actual value.

I would like to see the case for single constructor enums separated out and handled separately instead.

keeperofdakeys pushed a commit to keeperofdakeys/rust that referenced this issue Dec 12, 2017
bors pushed a commit to rust-lang-ci/rust that referenced this issue Oct 26, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Debuginfo locals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

5 participants