|
| 1 | +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +/// @assertion A constant expression is an expression whose value can never |
| 6 | +/// change, and that can be evaluated entirely at compile time. |
| 7 | +/// A constant expression is one of the following: |
| 8 | +/// ... |
| 9 | +/// • An expression of the form e is T is potentially constant if e is a |
| 10 | +/// potentially constant expression and T is a constant type expression, and |
| 11 | +/// it is further constant if e is constant. |
| 12 | +/// |
| 13 | +/// @description Checks that an expression of the form `e is T` is not a |
| 14 | +/// constant expression if `e` is not a constant expression |
| 15 | + |
| 16 | +
|
| 17 | +// SharedOptions=--enable-experiment=inline-class |
| 18 | + |
| 19 | +class C { |
| 20 | + C(); |
| 21 | +} |
| 22 | + |
| 23 | +extension type IntET1(int _) {} |
| 24 | +extension type IntET2(int _) implements int {} |
| 25 | + |
| 26 | +test<T>() { |
| 27 | + const c = T is Type; |
| 28 | +// ^ |
| 29 | +// [analyzer] unspecified |
| 30 | +// [cfe] unspecified |
| 31 | +} |
| 32 | + |
| 33 | +main() { |
| 34 | + int i = 1; |
| 35 | + var d = 3.14; |
| 36 | + var c = C(); |
| 37 | + |
| 38 | + const c1 = i is num; |
| 39 | +// ^ |
| 40 | +// [analyzer] unspecified |
| 41 | +// [cfe] unspecified |
| 42 | + const c2 = (d as num) is double; |
| 43 | +// ^ |
| 44 | +// [analyzer] unspecified |
| 45 | +// [cfe] unspecified |
| 46 | + const c3 = IntET1(1) is int; |
| 47 | +// ^^^^^^^^^ |
| 48 | +// [analyzer] unspecified |
| 49 | +// [cfe] unspecified |
| 50 | + const c4 = IntET2(1) is int; |
| 51 | +// ^^^^^^^^^ |
| 52 | +// [analyzer] unspecified |
| 53 | +// [cfe] unspecified |
| 54 | + const c5 = (i,) is (int,); |
| 55 | +// ^ |
| 56 | +// [analyzer] unspecified |
| 57 | +// [cfe] unspecified |
| 58 | + const c6 = (IntET1(1),) is (int,); |
| 59 | +// ^^^^^^^^^ |
| 60 | +// [analyzer] unspecified |
| 61 | +// [cfe] unspecified |
| 62 | + const c7 = (IntET2(1),) is (int,); |
| 63 | +// ^^^^^^^^^ |
| 64 | +// [analyzer] unspecified |
| 65 | +// [cfe] unspecified |
| 66 | + const c8 = [i] is List<int>; |
| 67 | +// ^ |
| 68 | +// [analyzer] unspecified |
| 69 | +// [cfe] unspecified |
| 70 | + const c9 = [IntET1(1)] is List<int>; |
| 71 | +// ^^^^^^^^^ |
| 72 | +// [analyzer] unspecified |
| 73 | +// [cfe] unspecified |
| 74 | + const c10 = [IntET2(1)] is List<num>; |
| 75 | +// ^^^^^^^^^ |
| 76 | +// [analyzer] unspecified |
| 77 | +// [cfe] unspecified |
| 78 | + const c11 = {d} is Set<num>; |
| 79 | +// ^ |
| 80 | +// [analyzer] unspecified |
| 81 | +// [cfe] unspecified |
| 82 | + const c12 = {IntET1(1)} is Set<num>; |
| 83 | +// ^^^^^^^^^ |
| 84 | +// [analyzer] unspecified |
| 85 | +// [cfe] unspecified |
| 86 | + const c13 = {IntET2(1)} is Set<num>; |
| 87 | +// ^^^^^^^^^ |
| 88 | +// [analyzer] unspecified |
| 89 | +// [cfe] unspecified |
| 90 | + const c14 = {IntET1(1): IntET1(2)} is Map<num, int>; |
| 91 | +// ^^^^^^^^^ |
| 92 | +// [analyzer] unspecified |
| 93 | +// [cfe] unspecified |
| 94 | + const c15 = {IntET2(1): IntET2(2)} is Map<num, int>; |
| 95 | +// ^^^^^^^^^ |
| 96 | +// [analyzer] unspecified |
| 97 | +// [cfe] unspecified |
| 98 | + const c16 = IntET1(1) is IntET2; |
| 99 | +// ^^^^^^^^^ |
| 100 | +// [analyzer] unspecified |
| 101 | +// [cfe] unspecified |
| 102 | + const c17 = IntET2(1) is IntET1; |
| 103 | +// ^^^^^^^^^ |
| 104 | +// [analyzer] unspecified |
| 105 | +// [cfe] unspecified |
| 106 | + const c19 = c is Object; |
| 107 | +// ^ |
| 108 | +// [analyzer] unspecified |
| 109 | +// [cfe] unspecified |
| 110 | +} |
0 commit comments