Skip to content

clarification on semantics of ??= #11

@sigmundch

Description

@sigmundch

Question for @gbracha and @stereotype441

The proposal says that the semantics of a ??= b are the same as:

  a = a ?? b

This means, a will be assigned it's own value when it's not null. This can be observable if you do:

get v => 1
set v(value) { print('setter was called with $value');
main() {
  v ??= 2; // prints "setter was called with 1"
  v ??= 3; // prints "setter was called with 1"
}

However, some tests are written with a different semantics that avoids the assignment if the value is not null. In other words:

  ((v) => v == null ? a = b : v)(a)

I currently have the former implemented in dart2js and I'm inclined to change those tests to match, but I wanted to verify this was the intended behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions