Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2557513008: Enable messages in asserts by default (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.src.generated.error_verifier; 5 library analyzer.src.generated.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 */ 289 */
290 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 290 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
291 291
292 /** 292 /**
293 * If `true`, mixins are allowed to inherit from types other than Object, and 293 * If `true`, mixins are allowed to inherit from types other than Object, and
294 * are allowed to reference `super`. 294 * are allowed to reference `super`.
295 */ 295 */
296 final bool enableSuperMixins; 296 final bool enableSuperMixins;
297 297
298 /** 298 /**
299 * If `true`, asserts are allowed to take a second argument representing the
300 * assertion failure message (see DEP 37).
301 */
302 final bool enableAssertMessage;
303
304 /**
305 * Initialize a newly created error verifier. 299 * Initialize a newly created error verifier.
306 */ 300 */
307 ErrorVerifier( 301 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider,
308 this._errorReporter, 302 this._inheritanceManager, this.enableSuperMixins) {
309 this._currentLibrary,
310 this._typeProvider,
311 this._inheritanceManager,
312 this.enableSuperMixins,
313 this.enableAssertMessage) {
314 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; 303 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
315 this._hasExtUri = _currentLibrary.hasExtUri; 304 this._hasExtUri = _currentLibrary.hasExtUri;
316 _isEnclosingConstructorConst = false; 305 _isEnclosingConstructorConst = false;
317 _isInCatchClause = false; 306 _isInCatchClause = false;
318 _isInStaticVariableDeclaration = false; 307 _isInStaticVariableDeclaration = false;
319 _isInInstanceVariableDeclaration = false; 308 _isInInstanceVariableDeclaration = false;
320 _isInInstanceVariableInitializer = false; 309 _isInInstanceVariableInitializer = false;
321 _isInConstructorInitializer = false; 310 _isInConstructorInitializer = false;
322 _isInStaticMethod = false; 311 _isInStaticMethod = false;
323 _boolType = _typeProvider.boolType; 312 _boolType = _typeProvider.boolType;
(...skipping 18 matching lines...) Expand all
342 331
343 @override 332 @override
344 Object visitAsExpression(AsExpression node) { 333 Object visitAsExpression(AsExpression node) {
345 _checkForTypeAnnotationDeferredClass(node.type); 334 _checkForTypeAnnotationDeferredClass(node.type);
346 return super.visitAsExpression(node); 335 return super.visitAsExpression(node);
347 } 336 }
348 337
349 @override 338 @override
350 Object visitAssertInitializer(AssertInitializer node) { 339 Object visitAssertInitializer(AssertInitializer node) {
351 _checkForNonBoolExpression(node); 340 _checkForNonBoolExpression(node);
352 _checkAssertMessage(node);
353 return super.visitAssertInitializer(node); 341 return super.visitAssertInitializer(node);
354 } 342 }
355 343
356 @override 344 @override
357 Object visitAssertStatement(AssertStatement node) { 345 Object visitAssertStatement(AssertStatement node) {
358 _checkForNonBoolExpression(node); 346 _checkForNonBoolExpression(node);
359 _checkAssertMessage(node);
360 return super.visitAssertStatement(node); 347 return super.visitAssertStatement(node);
361 } 348 }
362 349
363 @override 350 @override
364 Object visitAssignmentExpression(AssignmentExpression node) { 351 Object visitAssignmentExpression(AssignmentExpression node) {
365 TokenType operatorType = node.operator.type; 352 TokenType operatorType = node.operator.type;
366 Expression lhs = node.leftHandSide; 353 Expression lhs = node.leftHandSide;
367 Expression rhs = node.rightHandSide; 354 Expression rhs = node.rightHandSide;
368 if (operatorType == TokenType.EQ || 355 if (operatorType == TokenType.EQ ||
369 operatorType == TokenType.QUESTION_QUESTION_EQ) { 356 operatorType == TokenType.QUESTION_QUESTION_EQ) {
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; 1282 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR;
1296 } else { 1283 } else {
1297 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; 1284 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR;
1298 } 1285 }
1299 _errorReporter.reportErrorForNode(errorCode, node); 1286 _errorReporter.reportErrorForNode(errorCode, node);
1300 } 1287 }
1301 return super.visitYieldStatement(node); 1288 return super.visitYieldStatement(node);
1302 } 1289 }
1303 1290
1304 /** 1291 /**
1305 * If the given [assertion] specifies a message, verify that support
1306 * for assertions with messages is enabled.
1307 */
1308 void _checkAssertMessage(Assertion assertion) {
1309 Expression expression = assertion.message;
1310 if (expression != null && !enableAssertMessage) {
1311 _errorReporter.reportErrorForNode(
1312 CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression);
1313 }
1314 }
1315
1316 /**
1317 * Given a list of [directives] that have the same prefix, generate an error 1292 * Given a list of [directives] that have the same prefix, generate an error
1318 * if there is more than one import and any of those imports is deferred. 1293 * if there is more than one import and any of those imports is deferred.
1319 * 1294 *
1320 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]. 1295 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX].
1321 */ 1296 */
1322 void _checkDeferredPrefixCollision(List<ImportDirective> directives) { 1297 void _checkDeferredPrefixCollision(List<ImportDirective> directives) {
1323 int count = directives.length; 1298 int count = directives.length;
1324 if (count > 1) { 1299 if (count > 1) {
1325 for (int i = 0; i < count; i++) { 1300 for (int i = 0; i < count; i++) {
1326 Token deferredToken = directives[i].deferredKeyword; 1301 Token deferredToken = directives[i].deferredKeyword;
(...skipping 5645 matching lines...) Expand 10 before | Expand all | Expand 10 after
6972 class _InvocationCollector extends RecursiveAstVisitor { 6947 class _InvocationCollector extends RecursiveAstVisitor {
6973 final List<String> superCalls = <String>[]; 6948 final List<String> superCalls = <String>[];
6974 6949
6975 @override 6950 @override
6976 visitMethodInvocation(MethodInvocation node) { 6951 visitMethodInvocation(MethodInvocation node) {
6977 if (node.target is SuperExpression) { 6952 if (node.target is SuperExpression) {
6978 superCalls.add(node.methodName.name); 6953 superCalls.add(node.methodName.name);
6979 } 6954 }
6980 } 6955 }
6981 } 6956 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698