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

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

Issue 879093002: Fix mixin resolution order when multiple mixins present. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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/element_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 380829c002e00bc40d3fc7304f1c6b1ee39e7112..fa5921c1316343fbd8b635bed6007841c7e938ad 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -23,8 +23,8 @@ import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/static_type_analyzer.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
-import 'package:analyzer/src/generated/testing/test_type_provider.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
+import 'package:analyzer/src/generated/testing/test_type_provider.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:unittest/unittest.dart';
@@ -4606,6 +4606,29 @@ class InheritanceManagerTest extends EngineTestCase {
_assertNoErrors(classB);
}
+ void test_getMapOfMembersInheritedFromClasses_method_with_two_mixins() {
+ // class A1 { int m(); }
+ // class A2 { int m(); }
+ // class B extends Object with A1, A2 {}
+ ClassElementImpl classA1 = ElementFactory.classElement2("A1");
+ String methodName = "m";
+ MethodElement methodA1M =
+ ElementFactory.methodElement(methodName, _typeProvider.intType);
+ classA1.methods = <MethodElement>[methodA1M];
+ ClassElementImpl classA2 = ElementFactory.classElement2("A2");
+ MethodElement methodA2M =
+ ElementFactory.methodElement(methodName, _typeProvider.intType);
+ classA2.methods = <MethodElement>[methodA2M];
+ ClassElementImpl classB = ElementFactory.classElement2("B");
+ classB.mixins = <InterfaceType>[classA1.type, classA2.type];
+ MemberMap mapB =
+ _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
+ expect(mapB.get(methodName), same(methodA2M));
+ _assertNoErrors(classA1);
+ _assertNoErrors(classA2);
+ _assertNoErrors(classB);
+ }
+
void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() {
// class A { int get g; }
// class B extends A {}
@@ -6329,6 +6352,24 @@ 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;
@@ -6551,8 +6592,7 @@ library lib1;
f() {}''', r'''
library root;
import 'lib1.dart' deferred as lib1;
-main() { lib1.f(); }'''],
- ErrorCode.EMPTY_LIST);
+main() { lib1.f(); }'''], ErrorCode.EMPTY_LIST);
}
void test_issue20904BuggyTypePromotionAtIfJoin_1() {
@@ -6755,24 +6795,6 @@ class B extends A {
verify([source]);
}
- 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_proxy_annotation_prefixed() {
Source source = addSource(r'''
library L;
@@ -7880,13 +7902,6 @@ class ResolverTestCase extends EngineTestCase {
return null;
}
- void resolveWithErrors(List<String> strSources, List<ErrorCode> codes) {
- // Analysis and assertions
- Source source = resolveSources(strSources);
- assertErrors(source, codes);
- verify([source]);
- }
-
void resolveWithAndWithoutExperimental(List<String> strSources,
List<ErrorCode> codesWithoutExperimental,
List<ErrorCode> codesWithExperimental) {
@@ -7906,6 +7921,13 @@ class ResolverTestCase extends EngineTestCase {
verify([source]);
}
+ void resolveWithErrors(List<String> strSources, List<ErrorCode> codes) {
+ // Analysis and assertions
+ Source source = resolveSources(strSources);
+ assertErrors(source, codes);
+ verify([source]);
+ }
+
@override
void setUp() {
reset();
@@ -8036,6 +8058,44 @@ class ScopeTest_TestScope extends Scope {
@reflectiveTest
class SimpleResolverTest extends ResolverTestCase {
+ void fail_getter_and_setter_fromMixins_property_access() {
+ // TODO(paulberry): it appears that auxiliaryElements isn't properly set on
+ // a SimpleIdentifier that's inside a property access. This bug should be
+ // fixed.
+ Source source = addSource('''
+class B {}
+class M1 {
+ get x => null;
+ set x(value) {}
+}
+class M2 {
+ get x => null;
+ set x(value) {}
+}
+class C extends B with M1, M2 {}
+void main() {
+ new C().x += 1;
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that both the getter and setter for "x" in "new C().x" refer to
+ // the accessors defined in M2.
+ FunctionDeclaration main =
+ library.definingCompilationUnit.functions[0].node;
+ BlockFunctionBody body = main.functionExpression.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ AssignmentExpression assignment = stmt.expression;
+ PropertyAccess propertyAccess = assignment.leftHandSide;
+ expect(
+ propertyAccess.propertyName.staticElement.enclosingElement.name,
+ 'M2');
+ expect(
+ propertyAccess.propertyName.auxiliaryElements.staticElement.enclosingElement.name,
+ 'M2');
+ }
+
void fail_staticInvocation() {
Source source = addSource(r'''
class A {
@@ -8734,6 +8794,97 @@ class A {
verify([source]);
}
+ void test_getter_and_setter_fromMixins_bare_identifier() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ get x => null;
+ set x(value) {}
+}
+class M2 {
+ get x => null;
+ set x(value) {}
+}
+class C extends B with M1, M2 {
+ void f() {
+ x += 1;
+ }
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that both the getter and setter for "x" in C.f() refer to the
+ // accessors defined in M2.
+ ClassElement classC = library.definingCompilationUnit.types[3];
+ MethodDeclaration f = classC.getMethod('f').node;
+ BlockFunctionBody body = f.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ AssignmentExpression assignment = stmt.expression;
+ SimpleIdentifier leftHandSide = assignment.leftHandSide;
+ expect(leftHandSide.staticElement.enclosingElement.name, 'M2');
+ expect(
+ leftHandSide.auxiliaryElements.staticElement.enclosingElement.name,
+ 'M2');
+ }
+
+ void test_getter_fromMixins_bare_identifier() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ get x => null;
+}
+class M2 {
+ get x => null;
+}
+class C extends B with M1, M2 {
+ f() {
+ return x;
+ }
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the getter for "x" in C.f() refers to the getter defined in
+ // M2.
+ ClassElement classC = library.definingCompilationUnit.types[3];
+ MethodDeclaration f = classC.getMethod('f').node;
+ BlockFunctionBody body = f.body;
+ ReturnStatement stmt = body.block.statements[0];
+ SimpleIdentifier x = stmt.expression;
+ expect(x.staticElement.enclosingElement.name, 'M2');
+ }
+
+ void test_getter_fromMixins_property_access() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ get x => null;
+}
+class M2 {
+ get x => null;
+}
+class C extends B with M1, M2 {}
+void main() {
+ var y = new C().x;
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the getter for "x" in "new C().x" refers to the getter
+ // defined in M2.
+ FunctionDeclaration main =
+ library.definingCompilationUnit.functions[0].node;
+ BlockFunctionBody body = main.functionExpression.body;
+ VariableDeclarationStatement stmt = body.block.statements[0];
+ PropertyAccess propertyAccess = stmt.variables.variables[0].initializer;
+ expect(
+ propertyAccess.propertyName.staticElement.enclosingElement.name,
+ 'M2');
+ }
+
void test_getterAndSetterWithDifferentTypes() {
Source source = addSource(r'''
class A {
@@ -9228,6 +9379,87 @@ class C extends B with A {
verify([source]);
}
+ void test_method_fromMixins() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ void f() {}
+}
+class M2 {
+ void f() {}
+}
+class C extends B with M1, M2 {}
+void main() {
+ new C().f();
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the "f" in "new C().f()" refers to the "f" defined in M2.
+ FunctionDeclaration main =
+ library.definingCompilationUnit.functions[0].node;
+ BlockFunctionBody body = main.functionExpression.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ MethodInvocation expr = stmt.expression;
+ expect(expr.methodName.staticElement.enclosingElement.name, 'M2');
+ }
+
+ void test_method_fromMixins_bare_identifier() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ void f() {}
+}
+class M2 {
+ void f() {}
+}
+class C extends B with M1, M2 {
+ void g() {
+ f();
+ }
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the call to f() in C.g() refers to the method defined in M2.
+ ClassElement classC = library.definingCompilationUnit.types[3];
+ MethodDeclaration g = classC.getMethod('g').node;
+ BlockFunctionBody body = g.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ MethodInvocation invocation = stmt.expression;
+ SimpleIdentifier methodName = invocation.methodName;
+ expect(methodName.staticElement.enclosingElement.name, 'M2');
+ }
+
+ void test_method_fromMixins_invked_from_outside_class() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ void f() {}
+}
+class M2 {
+ void f() {}
+}
+class C extends B with M1, M2 {}
+void main() {
+ new C().f();
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the call to f() in "new C().f()" refers to the method
+ // defined in M2.
+ FunctionDeclaration main =
+ library.definingCompilationUnit.functions[0].node;
+ BlockFunctionBody body = main.functionExpression.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ MethodInvocation invocation = stmt.expression;
+ expect(invocation.methodName.staticElement.enclosingElement.name, 'M2');
+ }
+
void test_method_fromSuperclassMixin() {
Source source = addSource(r'''
class A {
@@ -9289,6 +9521,65 @@ f(var p) {
assertNoErrors(source);
}
+ void test_setter_fromMixins_bare_identifier() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ set x(value) {}
+}
+class M2 {
+ set x(value) {}
+}
+class C extends B with M1, M2 {
+ void f() {
+ x = 1;
+ }
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the setter for "x" in C.f() refers to the setter defined in
+ // M2.
+ ClassElement classC = library.definingCompilationUnit.types[3];
+ MethodDeclaration f = classC.getMethod('f').node;
+ BlockFunctionBody body = f.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ AssignmentExpression assignment = stmt.expression;
+ SimpleIdentifier leftHandSide = assignment.leftHandSide;
+ expect(leftHandSide.staticElement.enclosingElement.name, 'M2');
+ }
+
+ void test_setter_fromMixins_property_access() {
+ Source source = addSource('''
+class B {}
+class M1 {
+ set x(value) {}
+}
+class M2 {
+ set x(value) {}
+}
+class C extends B with M1, M2 {}
+void main() {
+ new C().x = 1;
+}
+''');
+ LibraryElement library = resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ // Verify that the setter for "x" in "new C().x" refers to the setter
+ // defined in M2.
+ FunctionDeclaration main =
+ library.definingCompilationUnit.functions[0].node;
+ BlockFunctionBody body = main.functionExpression.body;
+ ExpressionStatement stmt = body.block.statements[0];
+ AssignmentExpression assignment = stmt.expression;
+ PropertyAccess propertyAccess = assignment.leftHandSide;
+ expect(
+ propertyAccess.propertyName.staticElement.enclosingElement.name,
+ 'M2');
+ }
+
void test_setter_inherited() {
Source source = addSource(r'''
class A {
@@ -11191,6 +11482,101 @@ class TypeOverrideManagerTest extends EngineTestCase {
@reflectiveTest
class TypePropagationTest extends ResolverTestCase {
+ void fail_finalPropertyInducingVariable_classMember_instance() {
+ addNamedSource("/lib.dart", r'''
+class A {
+ final v = 0;
+}''');
+ String code = r'''
+import 'lib.dart';
+f(A a) {
+ return a.v; // marker
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
+ void fail_finalPropertyInducingVariable_classMember_instance_inherited() {
+ addNamedSource("/lib.dart", r'''
+class A {
+ final v = 0;
+}''');
+ String code = r'''
+import 'lib.dart';
+class B extends A {
+ m() {
+ return v; // marker
+ }
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
+ void
+ fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget() {
+ addNamedSource("/lib.dart", r'''
+class A {
+ final v = 0;
+}''');
+ String code = r'''
+import 'lib.dart';
+f(p) {
+ if (p is A) {
+ return p.v; // marker
+ }
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
+ void fail_finalPropertyInducingVariable_classMember_static() {
+ addNamedSource("/lib.dart", r'''
+class A {
+ static final V = 0;
+}''');
+ String code = r'''
+import 'lib.dart';
+f() {
+ return A.V; // marker
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
+ void fail_finalPropertyInducingVariable_topLevelVaraible_prefixed() {
+ addNamedSource("/lib.dart", "final V = 0;");
+ String code = r'''
+import 'lib.dart' as p;
+f() {
+ var v2 = p.V; // marker prefixed
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
+ void fail_finalPropertyInducingVariable_topLevelVaraible_simple() {
+ addNamedSource("/lib.dart", "final V = 0;");
+ String code = r'''
+import 'lib.dart';
+f() {
+ return V; // marker simple
+}''';
+ _assertTypeOfMarkedExpression(
+ code,
+ typeProvider.dynamicType,
+ typeProvider.intType);
+ }
+
void fail_mergePropagatedTypesAtJoinPoint_1() {
// https://code.google.com/p/dart/issues/detail?id=19929
_assertTypeOfMarkedExpression(r'''
@@ -11477,101 +11863,6 @@ main(CanvasElement canvas) {
expect(identifier.propagatedType.name, "CanvasRenderingContext2D");
}
- void fail_finalPropertyInducingVariable_classMember_instance() {
- addNamedSource("/lib.dart", r'''
-class A {
- final v = 0;
-}''');
- String code = r'''
-import 'lib.dart';
-f(A a) {
- return a.v; // marker
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
- void fail_finalPropertyInducingVariable_classMember_instance_inherited() {
- addNamedSource("/lib.dart", r'''
-class A {
- final v = 0;
-}''');
- String code = r'''
-import 'lib.dart';
-class B extends A {
- m() {
- return v; // marker
- }
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
- void
- fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget() {
- addNamedSource("/lib.dart", r'''
-class A {
- final v = 0;
-}''');
- String code = r'''
-import 'lib.dart';
-f(p) {
- if (p is A) {
- return p.v; // marker
- }
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
- void fail_finalPropertyInducingVariable_classMember_static() {
- addNamedSource("/lib.dart", r'''
-class A {
- static final V = 0;
-}''');
- String code = r'''
-import 'lib.dart';
-f() {
- return A.V; // marker
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
- void fail_finalPropertyInducingVariable_topLevelVaraible_prefixed() {
- addNamedSource("/lib.dart", "final V = 0;");
- String code = r'''
-import 'lib.dart' as p;
-f() {
- var v2 = p.V; // marker prefixed
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
- void fail_finalPropertyInducingVariable_topLevelVaraible_simple() {
- addNamedSource("/lib.dart", "final V = 0;");
- String code = r'''
-import 'lib.dart';
-f() {
- return V; // marker simple
-}''';
- _assertTypeOfMarkedExpression(
- code,
- typeProvider.dynamicType,
- typeProvider.intType);
- }
-
void test_forEach() {
String code = r'''
main() {
« no previous file with comments | « pkg/analyzer/test/generated/element_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698