-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #477: More tests for constant short circuit operations added.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A04_t31.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 [?]/[:] in constant expression | ||
* throws a compile error if condition is of incorrect type. | ||
* @author [email protected] | ||
*/ | ||
// SharedOptions=--enable-experiment=constant-update-2018 | ||
|
||
const s = "wrong condition"; | ||
const dynamic b = true; | ||
const dynamic d = "wrong dynamic"; | ||
const dynamic nil = null; | ||
|
||
class MyClass { | ||
final String res; | ||
const MyClass(dynamic cond) : res = cond ? "yes" : "no"; | ||
} | ||
|
||
|
||
main() { | ||
const res1 = MyClass(s); | ||
// ^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const res2 = MyClass(b); | ||
|
||
const res3 = MyClass(d); | ||
// ^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const res4 = MyClass(null); | ||
// ^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const res5 = MyClass(nil); | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const res6 = MyClass(10); | ||
// ^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
} |