041261f92f
Change-Id: I31d9f245f6dc1f34e13d026c95189f10f4dae75f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163663 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
62 lines
1.5 KiB
Dart
62 lines
1.5 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.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
/// Test that variables which are initialized to Null are inferred at type
|
|
/// `dynamic`.
|
|
|
|
var global0 = null;
|
|
var global1 = null as Null;
|
|
|
|
class Test {
|
|
static var static0 = null;
|
|
static var static1 = null as Null;
|
|
|
|
var instance0 = null;
|
|
var instance1 = null as Null;
|
|
}
|
|
|
|
/// For each category of variable and each style of initialization, we test that
|
|
/// the variable verify that the type is not `Never` by verifying that a value
|
|
/// of type `Object` may be assigned to it, and then check that the type is
|
|
/// `dynamic` (or `Never` which has been eliminated) by verifying that an
|
|
/// arbitrary method may be called on it.
|
|
|
|
void test() {
|
|
final Object three = 3;
|
|
{
|
|
global0 = three;
|
|
Expect.isFalse(global0.isEven);
|
|
global1 = three;
|
|
Expect.isFalse(global1.isEven);
|
|
}
|
|
{
|
|
Test.static0 = three;
|
|
Expect.isFalse(Test.static0.isEven);
|
|
Test.static1 = three;
|
|
Expect.isFalse(Test.static1.isEven);
|
|
}
|
|
{
|
|
var o = new Test();
|
|
o.instance0 = three;
|
|
Expect.isFalse(o.instance0.isEven);
|
|
o.instance1 = three;
|
|
Expect.isFalse(o.instance1.isEven);
|
|
}
|
|
{
|
|
var local0 = null;
|
|
var local1 = null as Null;
|
|
|
|
local0 = three;
|
|
Expect.isFalse(local0.isEven);
|
|
local1 = three;
|
|
Expect.isFalse(local1.isEven);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test();
|
|
}
|