blob: 1789a98e1a45f39fe6d6e175675abeb1fe8a1d3c [file] [log] [blame]
// 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.
/// @assertion The [??] operator only evaluates its second operand if the first
/// evaluates to [null], and the second operand must be a potentially constant
/// expression.
/// @description Checks that operator [??] throws a error if the first operand is
/// not [null] and the second one is not a potentially constant.
/// @author iarkh@unipro.ru
/// @issue 43258
dynamic d1 = "12345";
dynamic d2 = 11;
int i = 14;
dynamic d;
const int? const1 = 0;
const String? const2 = "testme";
main() {
const a1 = const1 ?? d1;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
const a2 = const2 ?? d2;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
const a3 = (14 as int?) ?? i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
const a4 = ("12345" as String?) ?? d;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}