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

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

Issue 971193003: Don't set a propagate type if the variable has already the same static type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index cf2ae8d8a0e6becc8b60297a916e6955c16a3e4d..589ab79f4db255702139761cec236a31ea2c4003 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -6266,24 +6266,6 @@ class MemberMapTest {
@reflectiveTest
class NonHintCodeTest extends ResolverTestCase {
- void fail_propagatedFieldType() {
- // From dartbug.com/20019
- Source source = addSource(r'''
-class A { }
-class X<T> {
- final x = new List<T>();
-}
-class Z {
- final X<A> y = new X<A>();
- foo() {
- y.x.add(new A());
- }
-}''');
- resolve(source);
- assertNoErrors(source);
- verify([source]);
- }
-
void test_deadCode_deadBlock_conditionalElse_debugConst() {
Source source = addSource(r'''
const bool DEBUG = true;
@@ -6712,6 +6694,23 @@ class B extends A {
verify([source]);
}
+ void test_propagatedFieldType() {
+ Source source = addSource(r'''
+class A { }
+class X<T> {
+ final x = new List<T>();
+}
+class Z {
+ final X<A> y = new X<A>();
+ foo() {
+ y.x.add(new A());
+ }
+}''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
void test_proxy_annotation_prefixed() {
Source source = addSource(r'''
library L;
@@ -11993,6 +11992,68 @@ f() {
expect(variableName.propagatedType, same(typeProvider.stringType));
}
+ void test_initializer_hasStaticType() {
+ Source source = addSource(r'''
+f() {
+ int v = 0;
+ return v;
+}''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ CompilationUnit unit = resolveCompilationUnit(source, library);
+ FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
+ BlockFunctionBody body =
+ function.functionExpression.body as BlockFunctionBody;
+ NodeList<Statement> statements = body.block.statements;
+ // Type of 'v' in declaration.
+ {
+ VariableDeclarationStatement statement =
+ statements[0] as VariableDeclarationStatement;
+ SimpleIdentifier variableName = statement.variables.variables[0].name;
+ expect(variableName.staticType, same(typeProvider.intType));
+ expect(variableName.propagatedType, isNull);
+ }
+ // Type of 'v' in reference.
+ {
+ ReturnStatement statement = statements[1] as ReturnStatement;
+ SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
+ expect(variableName.staticType, same(typeProvider.intType));
+ expect(variableName.propagatedType, isNull);
+ }
+ }
+
+ void test_initializer_hasStaticType_parameterized() {
+ Source source = addSource(r'''
+f() {
+ List<int> v = <int>[];
+ return v;
+}''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ CompilationUnit unit = resolveCompilationUnit(source, library);
+ FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
+ BlockFunctionBody body =
+ function.functionExpression.body as BlockFunctionBody;
+ NodeList<Statement> statements = body.block.statements;
+ // Type of 'v' in declaration.
+ {
+ VariableDeclarationStatement statement =
+ statements[0] as VariableDeclarationStatement;
+ SimpleIdentifier variableName = statement.variables.variables[0].name;
+ expect(variableName.staticType, isNotNull);
+ expect(variableName.propagatedType, isNull);
+ }
+ // Type of 'v' in reference.
+ {
+ ReturnStatement statement = statements[1] as ReturnStatement;
+ SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
+ expect(variableName.staticType, isNotNull);
+ expect(variableName.propagatedType, isNull);
+ }
+ }
+
void test_initializer_null() {
String code = r'''
main() {

Powered by Google App Engine
This is Rietveld 408576698