6bec589f00
Change-Id: Iff8a3ea624b7130cb09359fbc9787a98ba07c4e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364700 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
80 lines
1.7 KiB
Dart
80 lines
1.7 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
class Class {
|
|
int? field;
|
|
}
|
|
|
|
extension Extension on Class {
|
|
int? get property => field;
|
|
void set property(int? value) {
|
|
field = value;
|
|
}
|
|
|
|
int? method() => field;
|
|
|
|
testImplicitThis() {
|
|
expect(null, property);
|
|
expect(42, property ??= 42);
|
|
expect(42, property ??= 87);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
test1(null);
|
|
test2(new Class());
|
|
}
|
|
|
|
test1(Class? c) {
|
|
expect(null, c?.property);
|
|
expect(null, c?.method);
|
|
expect(null, c?.method());
|
|
expect(null, c?.property = 42);
|
|
expect(null, Extension(c)?.property ??= 42);
|
|
}
|
|
|
|
test2(Class? c) {
|
|
expect(null, c?.property);
|
|
expect(null, c?.method());
|
|
var tearOff = c?.method;
|
|
expect(null, tearOff!());
|
|
expect(42, c?.property = 42);
|
|
expect(42, tearOff());
|
|
|
|
expect(null, c?.property = null);
|
|
expect(42, c?.property = 42);
|
|
|
|
c?.property = null;
|
|
expect(null, c?.property);
|
|
expect(42, c?.property ??= 42);
|
|
expect(42, c?.property ??= 87);
|
|
|
|
expect(null, c?.property = null);
|
|
c?.property ??= 42;
|
|
expect(42, c?.property);
|
|
c?.property ??= 87;
|
|
expect(42, c?.property);
|
|
|
|
c?.property = null;
|
|
expect(null, c?.property);
|
|
expect(42, Extension(c)?.property ??= 42);
|
|
expect(42, Extension(c)?.property ??= 87);
|
|
|
|
c?.property = null;
|
|
expect(null, c?.property);
|
|
Extension(c)?.property ??= 42;
|
|
expect(42, c?.property);
|
|
Extension(c)?.property ??= 87;
|
|
expect(42, c?.property);
|
|
|
|
c?.property = null;
|
|
c?.testImplicitThis();
|
|
}
|
|
|
|
expect(expected, actual) {
|
|
if (expected != actual) {
|
|
throw 'Mismatch: expected=$expected, actual=$actual';
|
|
}
|
|
}
|