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

Unified Diff: pkg/analyzer/test/generated/static_type_warning_code_test.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/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 d98f837d29eb22ceffbf15c4851fa557bd16403b..00016d916a02a7004e5ee2719e20a2b7d5ee1d48 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -58,6 +58,30 @@ 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_await_flattened() {
Source source = addSource('''
import 'dart:async';

Powered by Google App Engine
This is Rietveld 408576698