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'; |