83b2c5d3c3
Change-Id: I72262910b590f93ca5de7b3286c226d5ecaf3276 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443803 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Nate Bosch <nbosch@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
82 lines
1.6 KiB
Dart
82 lines
1.6 KiB
Dart
// Copyright (c) 2024, 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.
|
|
|
|
import '../static_type_helper.dart';
|
|
|
|
test1(String a, num x) {
|
|
<dynamic, dynamic>{?a: (x as int)};
|
|
// ^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
x..expectStaticType<Exactly<int>>();
|
|
}
|
|
|
|
test2(String? a, num x) {
|
|
<dynamic, dynamic>{?a: (x as int)};
|
|
x..expectStaticType<Exactly<num>>();
|
|
}
|
|
|
|
test3(String a, bool b, num x) {
|
|
if (b) {
|
|
x as int;
|
|
} else {
|
|
<dynamic, dynamic>{?a: (throw 0)};
|
|
// ^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
|
|
// Unreachable.
|
|
}
|
|
x..expectStaticType<Exactly<int>>();
|
|
}
|
|
|
|
test4(String? a, bool b, num x) {
|
|
if (b) {
|
|
x as int;
|
|
} else {
|
|
<dynamic, dynamic>{?a: (throw 0)};
|
|
// Reachable.
|
|
}
|
|
x..expectStaticType<Exactly<num>>();
|
|
}
|
|
|
|
test5(String? a) {
|
|
return <dynamic, dynamic>{?a: a..expectStaticType<Exactly<String>>()};
|
|
}
|
|
|
|
test6(String? a) {
|
|
return <dynamic, dynamic>{a: a..expectStaticType<Exactly<String?>>()};
|
|
}
|
|
|
|
expectThrows(void Function() f) {
|
|
bool hasThrown = true;
|
|
try {
|
|
f();
|
|
hasThrown = false;
|
|
} catch (e) {}
|
|
|
|
if (!hasThrown) {
|
|
throw "Expected the function to throw.";
|
|
}
|
|
}
|
|
|
|
main() {
|
|
test1("", 0);
|
|
|
|
test2("", 0);
|
|
test2(null, 0);
|
|
|
|
test3("", true, 0);
|
|
expectThrows(() => test3("", false, 0));
|
|
|
|
test4("", true, 0);
|
|
expectThrows(() => test4("", false, 0));
|
|
test4(null, true, 0);
|
|
test4(null, false, 0);
|
|
|
|
test5(null);
|
|
test5("");
|
|
|
|
test6(null);
|
|
test5("");
|
|
}
|