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

Unified Diff: pkg/analyzer/test/generated/static_type_warning_code_test.dart

Issue 1309543011: Add support for assert statements with messages to the analyzer. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments. Created 5 years, 3 months 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
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | pkg/analyzer/test/generated/utilities_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/static_type_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index a14e8c8f8c1a3e21613726b8c53ab5fddf3366c1..47b6fbf16d4582eb784e7dc3f5f066914ab834bd 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -59,6 +59,42 @@ f() {}''');
assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
}
+ void test_assert_message_suppresses_type_promotion() {
+ // If a variable is assigned to inside the expression for an assert
+ // message, type promotion should be suppressed, just as it would be if the
+ // assignment occurred outside an assert statement. (Note that it is a
+ // dubious practice for the computation of an assert message to have side
+ // effects, since it is only evaluated if the assert fails).
+ resetWithOptions(new AnalysisOptionsImpl()..enableAssertMessage = true);
+ Source source = addSource('''
+class C {
+ void foo() {}
+}
+
+f(Object x) {
+ if (x is C) {
+ x.foo();
+ assert(true, () { x = new C(); return 'msg'; }());
+ }
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+ // Do not verify since `x.foo()` fails to resolve.
+ }
+
+ void test_assert_with_message_non_string() {
+ resetWithOptions(new AnalysisOptionsImpl()..enableAssertMessage = true);
+ Source source = addSource('''
+f() {
+ assert(false, 3);
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [StaticTypeWarningCode.ASSERT_MESSAGE_NON_STRING]);
+ verify([source]);
+ }
+
void test_await_flattened() {
Source source = addSource('''
import 'dart:async';
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | pkg/analyzer/test/generated/utilities_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698