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

Improve invalid operator assignment handling. #11449

Merged
merged 1 commit into from
Jan 10, 2014

Conversation

rcatolino
Copy link
Contributor

So far the following code

struct Foo;

fn main() {
  let mut t = Foo;
  let ref b = Foo;
  a += *b;
}

errors with

test.rs:15:3: 13:11 error: binary operation + cannot be applied to type `Foo`
test.rs:15   *a += *b;

Since assignment-operators are no longer expanded to left = left OP right but are independents operators it should be

test.rs:15:3: 13:11 error: binary operation += cannot be applied to type `Foo`
test.rs:15   *a += *b;

to make it clear that implementing Add for Foo is not gonna work. (cf issues #11143, #11344)

Besides that, we also need to typecheck the rhs expression even if the operator has no implementation, or we end up with unknown types for the nodes of the rhs and an ICE later on while resolving types. (once again cf #11143 and #11344).

This probably would get fixed with #5992, but in the meantime it's a confusing error to stumble upon.
@pcwalton, you wrote the original code, what do you think?
(closes #11143 and #11344)

@alexcrichton
Copy link
Member

It'd be nice to have a test for the new functionality in the compile-fail suite of tests.

The change to the enums and error messages seem fine to me, but what's with the new check_expr(fcx, rhs);, that's just recursing to perform more typechecking, right?

@rcatolino
Copy link
Contributor Author

Yes the check_expr is there because of the typechecking, issue I mentioned. (Causes the ICE described in #11143 and #11344).
Test added. Just to be sure, the tests in compile-fail will fail if an ICE arises right? Otherwise this one is quite useless.
About the enum, I changed it because semantically the old name wouldn't have been correct anymore : we are now using it to check the context of the BinOp (assignment or not) and not just whether we allow overload. I didn't want to confuse the people working on it in the future.

@rcatolino
Copy link
Contributor Author

oops, a test in compile-fail wasn't expecting this error message, I updated it. Retry?

bors added a commit that referenced this pull request Jan 10, 2014
…ichton

So far the following code
```
struct Foo;

fn main() {
  let mut t = Foo;
  let ref b = Foo;
  a += *b;
}
```
errors with 
```
test.rs:15:3: 13:11 error: binary operation + cannot be applied to type `Foo`
test.rs:15   *a += *b;
```
Since assignment-operators are no longer expanded to ```left = left OP right``` but are independents operators it should be 
```
test.rs:15:3: 13:11 error: binary operation += cannot be applied to type `Foo`
test.rs:15   *a += *b;
```
to make it clear that implementing Add for Foo is not gonna work. (cf issues #11143, #11344)

Besides that, we also need to typecheck the rhs expression even if the operator has no implementation, or we end up with unknown types for the nodes of the rhs and an ICE later on while resolving types. (once again cf #11143 and #11344).

This probably would get fixed with #5992, but in the meantime it's a confusing error to stumble upon.
@pcwalton, you wrote the original code, what do you think?
(closes #11143 and #11344)
@bors bors closed this Jan 10, 2014
@bors bors merged commit 02d8621 into rust-lang:master Jan 10, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 7, 2023
Should be final writing_tests commit

Fixes that book `FIXME`.

r? `@flip1995`
changelog: none
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

Successfully merging this pull request may close these issues.

"internal compiler error: no type for node 81"
3 participants