89967b83f5
Change-Id: I2c74003cf6bc9ca5dde7e982af053d6e9d54714d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134286 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
59 lines
1.2 KiB
Dart
59 lines
1.2 KiB
Dart
// Copyright (c) 2020, 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 = 0;
|
|
Class get next => this;
|
|
int operator [](int key) => key;
|
|
void operator []=(int key, int value) {}
|
|
}
|
|
|
|
main() {
|
|
test(new Class());
|
|
}
|
|
|
|
test(Class? c) {
|
|
c?.next.field; // ok
|
|
throwsInStrong(() => c?.field + 2); // error
|
|
++c?.field; // ok
|
|
c?.field++; // ok
|
|
throwsInStrong(() => (c?.next).field); // error
|
|
throwsInStrong(() => -c?.field); // error
|
|
|
|
c?.next[0].isEven; // ok
|
|
throwsInStrong(() => c?.next[0] + 2); // error
|
|
++c?.next[0]; // ok
|
|
c?.next[0]++; // ok
|
|
throwsInStrong(() => (c?.next[0]).isEven); // error
|
|
throwsInStrong(() => -c?.next[0]); // error
|
|
}
|
|
|
|
final bool inStrongMode = _inStrongMode();
|
|
|
|
bool _inStrongMode() {
|
|
var f = (String? s) {
|
|
s.length; // This will be an invalid expression in strong mode.
|
|
};
|
|
try {
|
|
f("foo");
|
|
} catch (e) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void throwsInStrong(void Function() f) {
|
|
if (inStrongMode) {
|
|
try {
|
|
f();
|
|
} catch (e) {
|
|
print(e);
|
|
return;
|
|
}
|
|
throw 'Expected exception.';
|
|
} else {
|
|
f();
|
|
}
|
|
}
|