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

+= desugars wrong #113

Open
nikomatsakis opened this issue Feb 8, 2022 · 2 comments
Open

+= desugars wrong #113

nikomatsakis opened this issue Feb 8, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@nikomatsakis
Copy link
Member

If you run

class Point(var x, var y)

async fn main() {
    p = Point(22, 44)
    test(p).x += 1
    print(p).await
}

async fn test(p) {
    print("Hi").await
    p
}

you get a panic right now:

thread 'main' panicked at 'cannot force local variable origin to be synthesized', components/dada-validate/src/validate/validator.rs:771:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In general, we need to improve this to desugar to

tmp = test(p).lease
tmp.x = tmp.x + 1

or something like that.

I bellieve that form should also work for e.g. foo.x += 1 (where you would get tmp = foo.lease)

@nikomatsakis nikomatsakis added the bug Something isn't working label Feb 8, 2022
@nikomatsakis
Copy link
Member Author

General area of the code:

syntax::ExprData::OpEq(lhs_expr, op, rhs_expr) => {
let result = try {
let (validated_opt_temp_expr, validated_lhs_place) =
self.validate_expr_as_place(*lhs_expr)?;
let validated_lhs_expr =
self.add(validated::ExprData::Give(validated_lhs_place), expr);
let validated_rhs_expr = self.validate_expr(*rhs_expr);
let validated_op = self.validated_op(*op);
let validated_op_expr = self.add(
validated::ExprData::Op(
validated_lhs_expr,
validated_op,
validated_rhs_expr,
),
expr,
);
let assign_expr = self.add(
validated::ExprData::Assign(validated_lhs_place, validated_op_expr),
expr,
);
self.maybe_seq(validated_opt_temp_expr, assign_expr, expr)
};
self.or_error(result, expr)
}

@nikomatsakis
Copy link
Member Author

I'm fixing this "en passane" in the modal harmony branch

@nikomatsakis nikomatsakis self-assigned this Mar 2, 2022
nikomatsakis added a commit to nikomatsakis/dada that referenced this issue Mar 2, 2022
nikomatsakis added a commit to nikomatsakis/dada that referenced this issue Mar 2, 2022
nikomatsakis added a commit to nikomatsakis/dada that referenced this issue Mar 3, 2022
nikomatsakis added a commit to nikomatsakis/dada that referenced this issue Mar 3, 2022
nikomatsakis added a commit to nikomatsakis/dada that referenced this issue Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant