OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // An update to this file must be followed by regenerating the corresponding | 5 // An update to this file must be followed by regenerating the corresponding |
6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory. | 6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory. |
7 // | 7 // |
8 // Every message in this file must have an id. Use `message_id.dart` in the | 8 // Every message in this file must have an id. Use `message_id.dart` in the |
9 // bin directory to generate a fresh one. | 9 // bin directory to generate a fresh one. |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 static final analysisOptionsWarning = new Category("AnalysisOptionsWarning"); | 71 static final analysisOptionsWarning = new Category("AnalysisOptionsWarning"); |
72 | 72 |
73 static final checkedModeCompileTimeError = | 73 static final checkedModeCompileTimeError = |
74 new Category("CheckedModeCompileTimeError"); | 74 new Category("CheckedModeCompileTimeError"); |
75 | 75 |
76 static final parserError = new Category("ParserError"); | 76 static final parserError = new Category("ParserError"); |
77 | 77 |
78 static final compileTimeError = new Category("CompileTimeError"); | 78 static final compileTimeError = new Category("CompileTimeError"); |
79 | 79 |
| 80 static final staticTypeWarning = new Category("StaticTypeWarning"); |
| 81 |
| 82 static final staticWarning = new Category("StaticWarning"); |
| 83 |
| 84 static final hint = new Category("Hint"); |
| 85 |
80 final String name; | 86 final String name; |
81 | 87 |
82 Category(this.name); | 88 Category(this.name); |
83 } | 89 } |
84 | 90 |
85 enum Platform { dart2js, analyzer, } | 91 enum Platform { dart2js, analyzer, } |
86 const dart2js = Platform.dart2js; | 92 const dart2js = Platform.dart2js; |
87 const analyzer = Platform.analyzer; | 93 const analyzer = Platform.analyzer; |
88 | 94 |
89 class Message { | 95 class Message { |
(...skipping 15 matching lines...) Expand all Loading... |
105 /// For example, "Const is not allowed on getters" may be a specialization of | 111 /// For example, "Const is not allowed on getters" may be a specialization of |
106 /// "The 'const' keyword is not allowed here". | 112 /// "The 'const' keyword is not allowed here". |
107 /// | 113 /// |
108 /// Examples of the specialized message, should trigger for the more generic | 114 /// Examples of the specialized message, should trigger for the more generic |
109 /// message, when the platform doesn't support the more specialized message. | 115 /// message, when the platform doesn't support the more specialized message. |
110 /// | 116 /// |
111 /// Specializations must have the same error-id (but not sub-id) as the more | 117 /// Specializations must have the same error-id (but not sub-id) as the more |
112 /// generic message. | 118 /// generic message. |
113 final String specializationOf; | 119 final String specializationOf; |
114 | 120 |
115 final Category category; | 121 /// The categories of this message. |
| 122 /// |
| 123 /// The same message can be used in multiple categories, for example, as |
| 124 /// hint and warning. |
| 125 final List<Category> categories; |
| 126 |
116 final String template; | 127 final String template; |
117 // The analyzer fills holes positionally (and not named). The following field | 128 // The analyzer fills holes positionally (and not named). The following field |
118 // overrides the order of the holes. | 129 // overrides the order of the holes. |
119 // For example the template "The argument #field in #cls is bad", could have | 130 // For example the template "The argument #field in #cls is bad", could have |
120 // the order `["cls", "field"]', which means that the analyzer would first | 131 // the order `["cls", "field"]', which means that the analyzer would first |
121 // provide the class `cls` and then only `field`. | 132 // provide the class `cls` and then only `field`. |
122 // This list is generally `null`, but when it is provided it must contain all | 133 // This list is generally `null`, but when it is provided it must contain all |
123 // holes. | 134 // holes. |
124 final List<String> templateHoleOrder; | 135 final List<String> templateHoleOrder; |
125 final String howToFix; | 136 final String howToFix; |
126 final List<String> options; | 137 final List<String> options; |
127 final List examples; | 138 final List examples; |
128 final List<Platform> usedBy; | 139 final List<Platform> usedBy; |
129 | 140 |
130 Message( | 141 Message( |
131 {this.id, | 142 {this.id, |
132 this.subId: 0, | 143 this.subId: 0, |
133 this.specializationOf: null, | 144 this.specializationOf: null, |
134 this.category, | 145 this.categories, |
135 this.template, | 146 this.template, |
136 this.templateHoleOrder, | 147 this.templateHoleOrder, |
137 this.howToFix, | 148 this.howToFix, |
138 this.options, | 149 this.options, |
139 this.usedBy: const [], | 150 this.usedBy: const [], |
140 this.examples}); | 151 this.examples}); |
141 } | 152 } |
142 | 153 |
143 String get messagesAsJson { | 154 String get messagesAsJson { |
144 var jsonified = {}; | 155 var jsonified = {}; |
145 MESSAGES.forEach((String name, Message message) { | 156 MESSAGES.forEach((String name, Message message) { |
146 jsonified[name] = { | 157 jsonified[name] = { |
147 'id': message.id, | 158 'id': message.id, |
148 'subId': message.subId, | 159 'subId': message.subId, |
149 'category': message.category.name, | 160 'categories': |
| 161 message.categories.map((category) => category.name).toList(), |
150 'template': message.template, | 162 'template': message.template, |
151 'templateHoleOrder': message.templateHoleOrder, | 163 'templateHoleOrder': message.templateHoleOrder, |
152 'howToFix': message.howToFix, | 164 'howToFix': message.howToFix, |
153 'options': message.options, | 165 'options': message.options, |
154 'usedBy': message.usedBy.map((platform) => platform.toString()).toList(), | 166 'usedBy': message.usedBy.map((platform) => platform.toString()).toList(), |
155 'examples': message.examples, | 167 'examples': message.examples, |
156 }; | 168 }; |
157 }); | 169 }); |
158 return new JsonEncoder.withIndent(' ').convert(jsonified); | 170 return new JsonEncoder.withIndent(' ').convert(jsonified); |
159 } | 171 } |
160 | 172 |
161 final Map<String, Message> MESSAGES = { | 173 final Map<String, Message> MESSAGES = { |
162 'exampleMessage': new Message( | 174 'exampleMessage': new Message( |
163 id: 'use an Id generated by bin/message_id.dart', | 175 id: 'use an Id generated by bin/message_id.dart', |
164 category: Category.analysisOptionsError, | 176 categories: [Category.analysisOptionsError], |
165 template: "#use #named #arguments", | 177 template: "#use #named #arguments", |
166 templateHoleOrder: ["arguments", "named", "use"], | 178 templateHoleOrder: ["arguments", "named", "use"], |
167 howToFix: "an explanation on how to fix things", | 179 howToFix: "an explanation on how to fix things", |
168 examples: [ | 180 examples: [ |
169 r''' | 181 r''' |
170 Some multiline example; | 182 Some multiline example; |
171 That generates the bug.''', | 183 That generates the bug.''', |
172 { | 184 { |
173 'fileA.dart': ''' | 185 'fileA.dart': ''' |
174 or a map from file to content. | 186 or a map from file to content. |
175 again multiline''', | 187 again multiline''', |
176 'fileB.dart': ''' | 188 'fileB.dart': ''' |
177 with possibly multiple files. | 189 with possibly multiple files. |
178 muliline too''' | 190 muliline too''' |
179 } | 191 } |
180 ]), | 192 ]), |
181 | 193 |
182 // Const constructors (factory or not) may not have a body. | 194 // Const constructors (factory or not) may not have a body. |
183 'CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY': new Message( | 195 'CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY': new Message( |
184 id: 'LGJGHW', | 196 id: 'LGJGHW', |
185 subId: 0, | 197 subId: 0, |
186 category: Category.parserError, | 198 categories: [Category.parserError], |
187 template: "Const constructor or factory can't have a body.", | 199 template: "Const constructor or factory can't have a body.", |
188 howToFix: "Remove the 'const' keyword or the body.", | 200 howToFix: "Remove the 'const' keyword or the body.", |
189 usedBy: [ | 201 usedBy: [dart2js], |
190 dart2js | |
191 ], | |
192 examples: const [ | 202 examples: const [ |
193 r""" | 203 r""" |
194 class C { | 204 class C { |
195 const C() {} | 205 const C() {} |
196 } | 206 } |
197 | 207 |
198 main() => new C();""", | 208 main() => new C();""", |
199 r""" | 209 r""" |
200 class C { | 210 class C { |
201 const factory C() {} | 211 const factory C() {} |
202 } | 212 } |
203 | 213 |
204 main() => new C();""" | 214 main() => new C();""" |
205 ]), | 215 ]), |
206 // Const constructors may not have a body. | 216 // Const constructors may not have a body. |
207 'CONST_CONSTRUCTOR_WITH_BODY': new Message( | 217 'CONST_CONSTRUCTOR_WITH_BODY': new Message( |
208 id: 'LGJGHW', | 218 id: 'LGJGHW', |
209 subId: 1, | 219 subId: 1, |
210 specializationOf: "CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY", | 220 specializationOf: "CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY", |
211 category: Category.parserError, | 221 categories: [Category.parserError], |
212 template: "Const constructor can't have a body.", | 222 template: "Const constructor can't have a body.", |
213 howToFix: "Try removing the 'const' keyword or the body.", | 223 howToFix: "Try removing the 'const' keyword or the body.", |
214 usedBy: [ | 224 usedBy: [analyzer], |
215 analyzer | |
216 ], | |
217 examples: const [ | 225 examples: const [ |
218 r""" | 226 r""" |
219 class C { | 227 class C { |
220 const C() {} | 228 const C() {} |
221 } | 229 } |
222 | 230 |
223 main() => new C();""" | 231 main() => new C();""" |
224 ]), | 232 ]), |
225 // Const constructor factories may only redirect (and must not have a body). | 233 // Const constructor factories may only redirect (and must not have a body). |
226 'CONST_FACTORY': new Message( | 234 'CONST_FACTORY': new Message( |
227 id: 'LGJGHW', | 235 id: 'LGJGHW', |
228 subId: 2, | 236 subId: 2, |
229 specializationOf: "CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY", | 237 specializationOf: "CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY", |
230 category: Category.parserError, | 238 categories: [Category.parserError], |
231 template: "Only redirecting factory constructors can be declared to " | 239 template: "Only redirecting factory constructors can be declared to " |
232 "be 'const'.", | 240 "be 'const'.", |
233 howToFix: "Try removing the 'const' keyword or replacing the body with " | 241 howToFix: "Try removing the 'const' keyword or replacing the body with " |
234 "'=' followed by a valid target.", | 242 "'=' followed by a valid target.", |
235 usedBy: [ | 243 usedBy: [analyzer], |
236 analyzer | |
237 ], | |
238 examples: const [ | 244 examples: const [ |
239 r""" | 245 r""" |
240 class C { | 246 class C { |
241 const factory C() {} | 247 const factory C() {} |
242 } | 248 } |
243 | 249 |
244 main() => new C();""" | 250 main() => new C();""" |
245 ]), | 251 ]), |
246 | 252 |
247 'EXTRANEOUS_MODIFIER': new Message( | 253 'EXTRANEOUS_MODIFIER': new Message( |
248 id: 'GRKIQE', | 254 id: 'GRKIQE', |
249 subId: 0, | 255 subId: 0, |
250 category: Category.parserError, | 256 categories: [Category.parserError], |
251 template: "Can't have modifier '#{modifier}' here.", | 257 template: "Can't have modifier '#{modifier}' here.", |
252 howToFix: "Try removing '#{modifier}'.", | 258 howToFix: "Try removing '#{modifier}'.", |
253 usedBy: [ | 259 usedBy: [dart2js], |
254 dart2js | |
255 ], | |
256 examples: const [ | 260 examples: const [ |
257 "var String foo; main(){}", | 261 "var String foo; main(){}", |
258 // "var get foo; main(){}", | 262 // "var get foo; main(){}", |
259 "var set foo; main(){}", | 263 "var set foo; main(){}", |
260 "var final foo; main(){}", | 264 "var final foo; main(){}", |
261 "var var foo; main(){}", | 265 "var var foo; main(){}", |
262 "var const foo; main(){}", | 266 "var const foo; main(){}", |
263 "var abstract foo; main(){}", | 267 "var abstract foo; main(){}", |
264 "var static foo; main(){}", | 268 "var static foo; main(){}", |
265 "var external foo; main(){}", | 269 "var external foo; main(){}", |
266 "get var foo; main(){}", | 270 "get var foo; main(){}", |
267 "set var foo; main(){}", | 271 "set var foo; main(){}", |
268 "final var foo; main(){}", | 272 "final var foo; main(){}", |
269 "var var foo; main(){}", | 273 "var var foo; main(){}", |
270 "const var foo; main(){}", | 274 "const var foo; main(){}", |
271 "abstract var foo; main(){}", | 275 "abstract var foo; main(){}", |
272 "static var foo; main(){}", | 276 "static var foo; main(){}", |
273 "external var foo; main(){}" | 277 "external var foo; main(){}" |
274 ]), | 278 ]), |
275 | 279 |
276 'EXTRANEOUS_MODIFIER_REPLACE': new Message( | 280 'EXTRANEOUS_MODIFIER_REPLACE': new Message( |
277 id: 'GRKIQE', | 281 id: 'GRKIQE', |
278 subId: 1, | 282 subId: 1, |
279 category: Category.parserError, | 283 categories: [Category.parserError], |
280 template: "Can't have modifier '#{modifier}' here.", | 284 template: "Can't have modifier '#{modifier}' here.", |
281 howToFix: "Try replacing modifier '#{modifier}' with 'var', 'final', " | 285 howToFix: "Try replacing modifier '#{modifier}' with 'var', 'final', " |
282 "or a type.", | 286 "or a type.", |
283 usedBy: [ | 287 usedBy: [dart2js], |
284 dart2js | |
285 ], | |
286 examples: const [ | 288 examples: const [ |
287 // "get foo; main(){}", | 289 // "get foo; main(){}", |
288 "set foo; main(){}", | 290 "set foo; main(){}", |
289 "abstract foo; main(){}", | 291 "abstract foo; main(){}", |
290 "static foo; main(){}", | 292 "static foo; main(){}", |
291 "external foo; main(){}" | 293 "external foo; main(){}" |
292 ]), | 294 ]), |
293 | 295 |
294 'CONST_CLASS': new Message( | 296 'CONST_CLASS': new Message( |
295 id: 'GRKIQE', | 297 id: 'GRKIQE', |
296 subId: 2, | 298 subId: 2, |
297 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 299 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
298 // example below triggers 'EXTRANEOUS_MODIFIER'. | 300 // example below triggers 'EXTRANEOUS_MODIFIER'. |
299 specializationOf: 'EXTRANEOUS_MODIFIER', | 301 specializationOf: 'EXTRANEOUS_MODIFIER', |
300 category: Category.parserError, | 302 categories: [Category.parserError], |
301 template: "Classes can't be declared to be 'const'", | 303 template: "Classes can't be declared to be 'const'", |
302 howToFix: "Try removing the 'const' keyword or moving to the class'" | 304 howToFix: "Try removing the 'const' keyword or moving to the class'" |
303 " constructor(s).", | 305 " constructor(s).", |
304 usedBy: [ | 306 usedBy: [analyzer], |
305 analyzer | |
306 ], | |
307 examples: const [ | 307 examples: const [ |
308 r""" | 308 r""" |
309 const class C {} | 309 const class C {} |
310 | 310 |
311 main() => new C(); | 311 main() => new C(); |
312 """ | 312 """ |
313 ]), | 313 ]), |
314 | 314 |
315 'CONST_METHOD': new Message( | 315 'CONST_METHOD': new Message( |
316 id: 'GRKIQE', | 316 id: 'GRKIQE', |
317 subId: 3, | 317 subId: 3, |
318 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 318 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
319 // example below triggers 'EXTRANEOUS_MODIFIER'. | 319 // example below triggers 'EXTRANEOUS_MODIFIER'. |
320 specializationOf: 'EXTRANEOUS_MODIFIER', | 320 specializationOf: 'EXTRANEOUS_MODIFIER', |
321 category: Category.parserError, | 321 categories: [Category.parserError], |
322 template: "Getters, setters and methods can't be declared to be 'const'", | 322 template: "Getters, setters and methods can't be declared to be 'const'", |
323 howToFix: "Try removing the 'const' keyword.", | 323 howToFix: "Try removing the 'const' keyword.", |
324 usedBy: [ | 324 usedBy: [analyzer], |
325 analyzer | |
326 ], | |
327 examples: const [ | 325 examples: const [ |
328 "const int foo() => 499; main() {}", | 326 "const int foo() => 499; main() {}", |
329 "const int get foo => 499; main() {}", | 327 "const int get foo => 499; main() {}", |
330 "const set foo(v) => 499; main() {}", | 328 "const set foo(v) => 499; main() {}", |
331 "class A { const int foo() => 499; } main() { new A(); }", | 329 "class A { const int foo() => 499; } main() { new A(); }", |
332 "class A { const int get foo => 499; } main() { new A(); }", | 330 "class A { const int get foo => 499; } main() { new A(); }", |
333 "class A { const set foo(v) => 499; } main() { new A(); }", | 331 "class A { const set foo(v) => 499; } main() { new A(); }", |
334 ]), | 332 ]), |
335 | 333 |
336 'CONST_ENUM': new Message( | 334 'CONST_ENUM': new Message( |
337 id: 'GRKIQE', | 335 id: 'GRKIQE', |
338 subId: 4, | 336 subId: 4, |
339 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 337 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
340 // example below triggers 'EXTRANEOUS_MODIFIER'. | 338 // example below triggers 'EXTRANEOUS_MODIFIER'. |
341 specializationOf: 'EXTRANEOUS_MODIFIER', | 339 specializationOf: 'EXTRANEOUS_MODIFIER', |
342 category: Category.parserError, | 340 categories: [Category.parserError], |
343 template: "Enums can't be declared to be 'const'", | 341 template: "Enums can't be declared to be 'const'", |
344 howToFix: "Try removing the 'const' keyword.", | 342 howToFix: "Try removing the 'const' keyword.", |
345 usedBy: [analyzer], | 343 usedBy: [analyzer], |
346 examples: const ["const enum Foo { x } main() {}",]), | 344 examples: const ["const enum Foo { x } main() {}",]), |
347 | 345 |
348 'CONST_TYPEDEF': new Message( | 346 'CONST_TYPEDEF': new Message( |
349 id: 'GRKIQE', | 347 id: 'GRKIQE', |
350 subId: 5, | 348 subId: 5, |
351 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 349 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
352 // example below triggers 'EXTRANEOUS_MODIFIER'. | 350 // example below triggers 'EXTRANEOUS_MODIFIER'. |
353 specializationOf: 'EXTRANEOUS_MODIFIER', | 351 specializationOf: 'EXTRANEOUS_MODIFIER', |
354 category: Category.parserError, | 352 categories: [Category.parserError], |
355 template: "Type aliases can't be declared to be 'const'", | 353 template: "Type aliases can't be declared to be 'const'", |
356 howToFix: "Try removing the 'const' keyword.", | 354 howToFix: "Try removing the 'const' keyword.", |
357 usedBy: [analyzer], | 355 usedBy: [analyzer], |
358 examples: const ["const typedef void Foo(); main() {}",]), | 356 examples: const ["const typedef void Foo(); main() {}",]), |
359 | 357 |
360 'CONST_AND_FINAL': new Message( | 358 'CONST_AND_FINAL': new Message( |
361 id: 'GRKIQE', | 359 id: 'GRKIQE', |
362 subId: 6, | 360 subId: 6, |
363 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 361 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
364 // example below triggers 'EXTRANEOUS_MODIFIER'. | 362 // example below triggers 'EXTRANEOUS_MODIFIER'. |
365 specializationOf: 'EXTRANEOUS_MODIFIER', | 363 specializationOf: 'EXTRANEOUS_MODIFIER', |
366 category: Category.parserError, | 364 categories: [Category.parserError], |
367 template: "Members can't be declared to be both 'const' and 'final'", | 365 template: "Members can't be declared to be both 'const' and 'final'", |
368 howToFix: "Try removing either the 'const' or 'final' keyword.", | 366 howToFix: "Try removing either the 'const' or 'final' keyword.", |
369 usedBy: [ | 367 usedBy: [analyzer], |
370 analyzer | |
371 ], | |
372 examples: const [ | 368 examples: const [ |
373 "final const int x = 499; main() {}", | 369 "final const int x = 499; main() {}", |
374 "const final int x = 499; main() {}", | 370 "const final int x = 499; main() {}", |
375 "class A { static final const int x = 499; } main() {}", | 371 "class A { static final const int x = 499; } main() {}", |
376 "class A { static const final int x = 499; } main() {}", | 372 "class A { static const final int x = 499; } main() {}", |
377 ]), | 373 ]), |
378 | 374 |
379 'CONST_AND_VAR': new Message( | 375 'CONST_AND_VAR': new Message( |
380 id: 'GRKIQE', | 376 id: 'GRKIQE', |
381 subId: 7, | 377 subId: 7, |
382 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the | 378 // The specialization could also be 'EXTRANEOUS_MODIFIER_REPLACE', but the |
383 // example below triggers 'EXTRANEOUS_MODIFIER'. | 379 // example below triggers 'EXTRANEOUS_MODIFIER'. |
384 specializationOf: 'EXTRANEOUS_MODIFIER', | 380 specializationOf: 'EXTRANEOUS_MODIFIER', |
385 category: Category.parserError, | 381 categories: [Category.parserError], |
386 template: "Members can't be declared to be both 'const' and 'var'", | 382 template: "Members can't be declared to be both 'const' and 'var'", |
387 howToFix: "Try removing either the 'const' or 'var' keyword.", | 383 howToFix: "Try removing either the 'const' or 'var' keyword.", |
388 usedBy: [ | 384 usedBy: [analyzer], |
389 analyzer | |
390 ], | |
391 examples: const [ | 385 examples: const [ |
392 "var const x = 499; main() {}", | 386 "var const x = 499; main() {}", |
393 "const var x = 499; main() {}", | 387 "const var x = 499; main() {}", |
394 "class A { var const x = 499; } main() {}", | 388 "class A { var const x = 499; } main() {}", |
395 "class A { const var x = 499; } main() {}", | 389 "class A { const var x = 499; } main() {}", |
396 ]), | 390 ]), |
397 | 391 |
398 'CLASS_IN_CLASS': new Message( | 392 'CLASS_IN_CLASS': new Message( |
399 // Dart2js currently reports this as an EXTRANEOUS_MODIFIER error. | 393 // Dart2js currently reports this as an EXTRANEOUS_MODIFIER error. |
400 // TODO(floitsch): make dart2js use this error instead. | 394 // TODO(floitsch): make dart2js use this error instead. |
401 id: 'DOTHQH', | 395 id: 'DOTHQH', |
402 category: Category.parserError, | 396 categories: [Category.parserError], |
403 template: "Classes can't be declared inside other classes.", | 397 template: "Classes can't be declared inside other classes.", |
404 howToFix: "Try moving the class to the top-level.", | 398 howToFix: "Try moving the class to the top-level.", |
405 usedBy: [analyzer], | 399 usedBy: [analyzer], |
406 examples: const ["class A { class B {} } main() { new A(); }",]), | 400 examples: const ["class A { class B {} } main() { new A(); }",]), |
407 | 401 |
408 'CONSTRUCTOR_WITH_RETURN_TYPE': new Message( | 402 'CONSTRUCTOR_WITH_RETURN_TYPE': new Message( |
409 id: 'VOJBWY', | 403 id: 'VOJBWY', |
410 category: Category.parserError, | 404 categories: [Category.parserError], |
411 template: "Constructors can't have a return type", | 405 template: "Constructors can't have a return type", |
412 howToFix: "Try removing the return type.", | 406 howToFix: "Try removing the return type.", |
413 usedBy: [analyzer, dart2js], | 407 usedBy: [analyzer, dart2js], |
414 examples: const ["class A { int A() {} } main() { new A(); }",]), | 408 examples: const ["class A { int A() {} } main() { new A(); }",]), |
415 | 409 |
416 'MISSING_EXPRESSION_IN_THROW': new Message( | 410 'MISSING_EXPRESSION_IN_THROW': new Message( |
417 id: 'FTGGMJ', | 411 id: 'FTGGMJ', |
418 subId: 0, | 412 subId: 0, |
419 category: Category.parserError, | 413 categories: [Category.parserError], |
420 template: "Missing expression after 'throw'.", | 414 template: "Missing expression after 'throw'.", |
421 howToFix: "Did you mean 'rethrow'?", | 415 howToFix: "Did you mean 'rethrow'?", |
422 usedBy: [ | 416 usedBy: [analyzer, dart2js], |
423 analyzer, | |
424 dart2js | |
425 ], | |
426 examples: const [ | 417 examples: const [ |
427 'main() { throw; }', | 418 'main() { throw; }', |
428 'main() { try { throw 0; } catch(e) { throw; } }' | 419 'main() { try { throw 0; } catch(e) { throw; } }' |
429 ]), | 420 ]), |
430 | 421 |
431 /** | 422 /** |
432 * 12.8.1 Rethrow: It is a compile-time error if an expression of the form | 423 * 12.8.1 Rethrow: It is a compile-time error if an expression of the form |
433 * <i>rethrow;</i> is not enclosed within a on-catch clause. | 424 * <i>rethrow;</i> is not enclosed within a on-catch clause. |
434 */ | 425 */ |
435 'RETHROW_OUTSIDE_CATCH': new Message( | 426 'RETHROW_OUTSIDE_CATCH': new Message( |
436 id: 'MWETLC', | 427 id: 'MWETLC', |
437 category: Category.compileTimeError, | 428 categories: [Category.compileTimeError], |
438 template: 'Rethrow must be inside of catch clause', | 429 template: 'Rethrow must be inside of catch clause', |
439 howToFix: "Try moving the expression into a catch clause, or " | 430 howToFix: "Try moving the expression into a catch clause, or " |
440 "using a 'throw' expression.", | 431 "using a 'throw' expression.", |
441 usedBy: [analyzer, dart2js], | 432 usedBy: [analyzer, dart2js], |
442 examples: const ["main() { rethrow; }"]), | 433 examples: const ["main() { rethrow; }"]), |
443 | 434 |
444 /** | 435 /** |
445 * 13.12 Return: It is a compile-time error if a return statement of the form | 436 * 13.12 Return: It is a compile-time error if a return statement of the form |
446 * <i>return e;</i> appears in a generative constructor. | 437 * <i>return e;</i> appears in a generative constructor. |
447 */ | 438 */ |
448 'RETURN_IN_GENERATIVE_CONSTRUCTOR': new Message( | 439 'RETURN_IN_GENERATIVE_CONSTRUCTOR': new Message( |
449 id: 'UOTDQH', | 440 id: 'UOTDQH', |
450 category: Category.compileTimeError, | 441 categories: [Category.compileTimeError], |
451 template: "Constructors can't return values.", | 442 template: "Constructors can't return values.", |
452 howToFix: | 443 howToFix: |
453 "Try removing the return statement or using a factory constructor.", | 444 "Try removing the return statement or using a factory constructor.", |
454 usedBy: [ | 445 usedBy: [analyzer, dart2js], |
455 analyzer, | |
456 dart2js | |
457 ], | |
458 examples: const [ | 446 examples: const [ |
459 """ | 447 """ |
460 class C { | 448 class C { |
461 C() { | 449 C() { |
462 return 1; | 450 return 1; |
463 } | 451 } |
464 } | 452 } |
465 | 453 |
466 main() => new C();""" | 454 main() => new C();""" |
467 ]), | 455 ]), |
468 | 456 |
469 /** | 457 /** |
470 * 13.12 Return: It is a compile-time error if a return statement of the form | 458 * 13.12 Return: It is a compile-time error if a return statement of the form |
471 * <i>return e;</i> appears in a generator function. | 459 * <i>return e;</i> appears in a generator function. |
472 */ | 460 */ |
473 'RETURN_IN_GENERATOR': new Message( | 461 'RETURN_IN_GENERATOR': new Message( |
474 id: 'JRUTUQ', | 462 id: 'JRUTUQ', |
475 subId: 0, | 463 subId: 0, |
476 category: Category.compileTimeError, | 464 categories: [Category.compileTimeError], |
477 template: "Can't return a value from a generator function " | 465 template: "Can't return a value from a generator function " |
478 "(using the '#{modifier}' modifier).", | 466 "(using the '#{modifier}' modifier).", |
479 howToFix: "Try removing the value, replacing 'return' with 'yield' or" | 467 howToFix: "Try removing the value, replacing 'return' with 'yield' or" |
480 " changing the method body modifier", | 468 " changing the method body modifier", |
481 usedBy: [ | 469 usedBy: [analyzer, dart2js], |
482 analyzer, | |
483 dart2js | |
484 ], | |
485 examples: const [ | 470 examples: const [ |
486 """ | 471 """ |
487 foo() async* { return 0; } | 472 foo() async* { return 0; } |
488 main() => foo(); | 473 main() => foo(); |
489 """, | 474 """, |
490 """ | 475 """ |
491 foo() sync* { return 0; } | 476 foo() sync* { return 0; } |
492 main() => foo(); | 477 main() => foo(); |
493 """ | 478 """ |
494 ]), | 479 ]), |
| 480 |
| 481 'NOT_ASSIGNABLE': new Message( |
| 482 id: 'FYQYXB', |
| 483 subId: 0, |
| 484 categories: [Category.staticTypeWarning], |
| 485 template: "'#{fromType}' is not assignable to '#{toType}'.", |
| 486 usedBy: [dart2js]), |
| 487 |
| 488 'FORIN_NOT_ASSIGNABLE': new Message( |
| 489 id: 'FYQYXB', |
| 490 subId: 1, |
| 491 categories: [Category.hint], |
| 492 template: "The element type '#{currentType}' of '#{expressionType}' " |
| 493 "is not assignable to '#{elementType}'.", |
| 494 usedBy: [dart2js], |
| 495 examples: const [ |
| 496 """ |
| 497 main() { |
| 498 List<int> list = <int>[1, 2]; |
| 499 for (String x in list) x; |
| 500 } |
| 501 """ |
| 502 ]), |
| 503 |
| 504 /** |
| 505 * 13.11 Return: It is a static type warning if the type of <i>e</i> may not |
| 506 * be assigned to the declared return type of the immediately enclosing |
| 507 * function. |
| 508 */ |
| 509 'RETURN_OF_INVALID_TYPE': new Message( |
| 510 id: 'FYQYXB', |
| 511 subId: 2, |
| 512 specializationOf: 'NOT_ASSIGNABLE', |
| 513 categories: [Category.staticTypeWarning], |
| 514 template: "The return type '#{fromType}' is not a '#{toType}', as " |
| 515 "defined by the method '#{method}'.", |
| 516 usedBy: [analyzer], |
| 517 examples: const ["int foo() => 'foo'; main() { foo(); }"]), |
| 518 |
| 519 /** |
| 520 * 12.11.1 New: It is a static warning if the static type of <i>a<sub>i</sub>, |
| 521 * 1 <= i <= n+ k</i> may not be assigned to the type of the |
| 522 * corresponding formal parameter of the constructor <i>T.id</i> (respectively |
| 523 * <i>T</i>). |
| 524 * |
| 525 * 12.11.2 Const: It is a static warning if the static type of |
| 526 * <i>a<sub>i</sub>, 1 <= i <= n+ k</i> may not be assigned to the type |
| 527 * of the corresponding formal parameter of the constructor <i>T.id</i> |
| 528 * (respectively <i>T</i>). |
| 529 * |
| 530 * 12.14.2 Binding Actuals to Formals: Let <i>T<sub>i</sub></i> be the static |
| 531 * type of <i>a<sub>i</sub></i>, let <i>S<sub>i</sub></i> be the type of |
| 532 * <i>p<sub>i</sub>, 1 <= i <= n+k</i> and let <i>S<sub>q</sub></i> be |
| 533 * the type of the named parameter <i>q</i> of <i>f</i>. It is a static |
| 534 * warning if <i>T<sub>j</sub></i> may not be assigned to <i>S<sub>j</sub>, 1 |
| 535 * <= j <= m</i>. |
| 536 * |
| 537 * 12.14.2 Binding Actuals to Formals: Furthermore, each <i>q<sub>i</sub>, 1 |
| 538 * <= i <= l</i>, must have a corresponding named parameter in the set |
| 539 * <i>{p<sub>n+1</sub>, … p<sub>n+k</sub>}</i> or a static warning |
| 540 * occurs. It is a static warning if <i>T<sub>m+j</sub></i> may not be |
| 541 * assigned to <i>S<sub>r</sub></i>, where <i>r = q<sub>j</sub>, 1 <= j |
| 542 * <= l</i>. |
| 543 */ |
| 544 'ARGUMENT_TYPE_NOT_ASSIGNABLE': new Message( |
| 545 id: 'FYQYXB', |
| 546 subId: 3, |
| 547 specializationOf: 'NOT_ASSIGNABLE', |
| 548 categories: [Category.hint, Category.staticWarning], |
| 549 template: "The argument type '#{fromType}' cannot be assigned to the " |
| 550 "parameter type '#{toType}'.", |
| 551 usedBy: [analyzer], |
| 552 // TODO(floitsch): support hint warnings and ways to specify which |
| 553 // category an example should trigger for. |
| 554 examples: const ["foo(int x) => x; main() { foo('bar'); }"]), |
495 }; | 555 }; |
OLD | NEW |