blob: 93a276ae0263276d62d2e2787723d6e7480b4eca [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 Finally, the conditional [?]/[:] operator only evaluates one of
* its branches, depending on whether the condition expression evaluates to
* [true] or [false]. The other branch must also be a potentially constant
* expression.
* @description Checks that conditional operator [?]/[:] rejects the second
* operand if condition is [true] for constant expressions.
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
import "../../Utils/expect.dart";
class MyClass {
final int res;
const MyClass() : res = (true ? 125 : (null as String).length > 0);
}
main() {
const MyClass c1 = MyClass();
Expect.equals(125, c1.res);
const String str = true ? "OK" : (null as String).length < 14;
Expect.equals("OK", str);
const String str1 = true ? "OK" : "wrong";
Expect.equals("OK", str1);
}