|
| 1 | +// Copyright (c) 2023, 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 | +// SharedOptions=--enable-experiment=inline-class |
| 6 | + |
| 7 | +// Regression check for https://dartbug.com/53625 |
| 8 | +// |
| 9 | +// Extension type declarations must have a "representation declaration" |
| 10 | +// of the form: '(' <metadata> <type> <identifier> ')' |
| 11 | +// where `<metadata>` can be empty, the other two not. |
| 12 | +// |
| 13 | +// Any other format is (currently) disallowed. |
| 14 | + |
| 15 | + |
| 16 | +// The "representation declaration" is like the parameter list of |
| 17 | +// an implicit constructor. |
| 18 | +// It still does not accept any other parameter list shape than the above. |
| 19 | + |
| 20 | +extension type E00(int) {} |
| 21 | +// ^^^ |
| 22 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE |
| 23 | +// ^ |
| 24 | +// [cfe] unspecified |
| 25 | + |
| 26 | +extension type E01(int x,) {} |
| 27 | +// ^ |
| 28 | +// [analyzer] unspecified |
| 29 | +// [cfe] unspecified |
| 30 | + |
| 31 | +extension type E02(final int x) {} |
| 32 | +// ^^^^^ |
| 33 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 34 | +// [cfe] unspecified |
| 35 | + |
| 36 | +extension type E03(var x) {} |
| 37 | +// ^^^ |
| 38 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE |
| 39 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 40 | +// [cfe] unspecified |
| 41 | + |
| 42 | +extension type E04(final x) {} |
| 43 | +// ^^^^^ |
| 44 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE |
| 45 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 46 | +// [cfe] unspecified |
| 47 | + |
| 48 | +extension type E05(covariant int x) {} |
| 49 | +// ^ |
| 50 | +// [cfe] unspecified |
| 51 | + |
| 52 | +extension type E06(required int x) {} |
| 53 | +// ^^^^^^^^ |
| 54 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 55 | +// [cfe] unspecified |
| 56 | + |
| 57 | +extension type E07(int this.x) {} // Initializing formal. |
| 58 | +// ^^^^^^ |
| 59 | +// [analyzer] unspecified |
| 60 | +// [cfe] unspecified |
| 61 | + |
| 62 | +extension type E08(this.x) {} // Initializing formal. |
| 63 | +// ^^^^^^ |
| 64 | +// [analyzer] unspecified |
| 65 | +// [cfe] unspecified |
| 66 | + |
| 67 | +extension type E09(int super.x) implements E {} // Constructor super-parameter. |
| 68 | +// ^^^^^^^ |
| 69 | +// [analyzer] unspecified |
| 70 | +// [cfe] unspecified |
| 71 | + |
| 72 | +extension type E10(super.x) implements E {} // Constructor super-parameter. |
| 73 | +// ^^^^^^^ |
| 74 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 75 | +// [cfe] unspecified |
| 76 | + |
| 77 | +extension type E11(int x()) {} // Old-style function parameter syntax. |
| 78 | +// ^^^^^^^ |
| 79 | +// [analyzer] unspecified |
| 80 | +// [cfe] unspecified |
| 81 | + |
| 82 | +// The "primary parameter" declares a "field", |
| 83 | +// but still does not accept field modifiers or initializers. |
| 84 | + |
| 85 | +extension type E12(late int x) {} |
| 86 | +// ^^^^ |
| 87 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 88 | +// [cfe] unspecified |
| 89 | + |
| 90 | +extension type E13(int x = 0) {} |
| 91 | +// ^^^ |
| 92 | +// [analyzer] unspecified |
| 93 | +// [cfe] unspecified |
| 94 | + |
| 95 | +extension type E14(static int x) {} |
| 96 | +// ^^^^^^ |
| 97 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 98 | +// [cfe] unspecified |
| 99 | + |
| 100 | +extension type const E15(const int x) {} |
| 101 | +// ^^^^^ |
| 102 | +// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER |
| 103 | +// [cfe] unspecified |
| 104 | + |
| 105 | +// Precisely one parameter is allowed and required. |
| 106 | + |
| 107 | +extension type E16() {} |
| 108 | +// ^ |
| 109 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 110 | +// [cfe] unspecified |
| 111 | + |
| 112 | +extension type E17(int x, String y) {} |
| 113 | +// ^ |
| 114 | +// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS |
| 115 | +// [cfe] unspecified |
| 116 | + |
| 117 | +extension type E18(int x, [String y = "2"]) {} |
| 118 | +// ^ |
| 119 | +// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS |
| 120 | +// [cfe] unspecified |
| 121 | + |
| 122 | +extension type E19(int x, {required String y}) {} |
| 123 | +// ^ |
| 124 | +// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS |
| 125 | +// [cfe] unspecified |
| 126 | + |
| 127 | +extension type E20(int x, {String y = "2"}) {} |
| 128 | +// ^ |
| 129 | +// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS |
| 130 | +// [cfe] unspecified |
| 131 | + |
| 132 | +extension type E21([int x = 0]) {} |
| 133 | +// ^ |
| 134 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 135 | +// [cfe] unspecified |
| 136 | + |
| 137 | +extension type E22([int x = 0, int y = 0]) {} |
| 138 | +// ^ |
| 139 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 140 | +// [cfe] unspecified |
| 141 | + |
| 142 | +extension type E23({required int x}) {} |
| 143 | +// ^ |
| 144 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 145 | +// [cfe] unspecified |
| 146 | + |
| 147 | +extension type E24({int x = 0}) {} |
| 148 | +// ^ |
| 149 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 150 | +// [cfe] unspecified |
| 151 | + |
| 152 | +extension type E25({int x = 0, int y = 0}) {} |
| 153 | +// ^ |
| 154 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD |
| 155 | +// [cfe] unspecified |
| 156 | + |
| 157 | +// Annotations are allowed, but only at the start. |
| 158 | + |
| 159 | +extension type E26(@anno int) {} |
| 160 | +// ^ |
| 161 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE |
| 162 | +// ^ |
| 163 | +// [cfe] unspecified |
| 164 | + |
| 165 | +extension type E27(int @anno x) {} |
| 166 | +// ^^^ |
| 167 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE |
| 168 | +// ^ |
| 169 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN |
| 170 | +// [cfe] unspecified |
| 171 | + |
| 172 | +extension type E28(int x @anno) {} |
| 173 | +// ^ |
| 174 | +// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN |
| 175 | +// [cfe] unspecified |
| 176 | + |
| 177 | + |
| 178 | +// Helpers |
| 179 | +const anno = "Annotation"; |
| 180 | + |
| 181 | +extension type E(int x) {} |
| 182 | + |
| 183 | +void main() {} |
0 commit comments