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

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 1480433002: Add support for assert statements with messages to the analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index f76ab0919a2bc899b554603919ee3e148e628c0d..7295f65a64e3f0a4f3677473021995735dc5747f 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -266,10 +266,21 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
final bool enableSuperMixins;
/**
+ * If `true`, asserts are allowed to take a second argument representing the
+ * assertion failure message (see DEP 37).
+ */
+ final bool enableAssertMessage;
+
+ /**
* Initialize a newly created error verifier.
*/
- ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider,
- this._inheritanceManager, this.enableSuperMixins) {
+ ErrorVerifier(
+ this._errorReporter,
+ this._currentLibrary,
+ this._typeProvider,
+ this._inheritanceManager,
+ this.enableSuperMixins,
+ this.enableAssertMessage) {
this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
this._hasExtUri = _currentLibrary.hasExtUri;
_isEnclosingConstructorConst = false;
@@ -306,6 +317,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitAssertStatement(AssertStatement node) {
_checkForNonBoolExpression(node);
+ _checkAssertMessage(node);
return super.visitAssertStatement(node);
}
@@ -1117,6 +1129,19 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
/**
+ * If the given assert [statement] specifies a message, verify that support
+ * for assertions with messages is enabled.
+ */
+ void _checkAssertMessage(AssertStatement statement) {
+ Expression expression = statement.message;
+ if (expression != null && !enableAssertMessage) {
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression);
+ return;
+ }
+ }
+
+ /**
* Verify that the given list of [typeArguments] contains exactly two
* elements.
*

Powered by Google App Engine
This is Rietveld 408576698