Files
sdk/pkg/kernel/testcases/input/null_aware.dart
T
Asger Feldthaus 37c5809ccc [kernel] Always store the type of a conditional expressions on the node.
Previously, the type of a conditional expression could be omitted if
one of the arms was just a null literal. This was meant to simplify
translation into kernel, but wasn't really worth it in terms of
complexity, and it does not work well for types that carry nullability
information.

BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2465263002 .
2016-11-01 16:04:10 +01:00

21 lines
505 B
Dart

// Copyright (c) 2016, 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 Foo {
int field;
static int staticField;
}
main() {
Foo foo = new Foo();
foo?.field = 5;
Foo?.staticField = 5;
foo.field ??= 5;
Foo.staticField ??= 5;
foo?.field ??= 5;
Foo?.staticField ??= 5;
int intValue = foo.field ?? 6;
num numValue = foo.field ?? 4.5;
}