dada-lang / dada

I speak only of myself since I do not wish to convince, I have no right to drag others into my river, I oblige no one to follow me and everybody practices his art in his own way.
https://dada-lang.org
Apache License 2.0
444 stars 28 forks source link

`+=` desugars wrong #113

Open nikomatsakis opened 2 years ago

nikomatsakis commented 2 years ago

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 commented 2 years ago

General area of the code:

https://github.com/dada-lang/dada/blob/00893256679e3bb89bcaf7c92fcb4db28917cdb2/components/dada-validate/src/validate/validator.rs#L379-L402

nikomatsakis commented 2 years ago

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