Index: pkg/kernel/test/class_hierarchy_test.dart |
diff --git a/pkg/kernel/test/class_hierarchy_test.dart b/pkg/kernel/test/class_hierarchy_test.dart |
index a05464f29ffa61529b30cb5894526927b29202b5..b4040a6536c702f2081ecaec2a707afd1ade9a8d 100644 |
--- a/pkg/kernel/test/class_hierarchy_test.dart |
+++ b/pkg/kernel/test/class_hierarchy_test.dart |
@@ -129,6 +129,13 @@ abstract class _ClassHierarchyTest { |
ClassHierarchy createClassHierarchy(Program program); |
+ Procedure newEmptyGetter(String name, |
+ {DartType returnType: const DynamicType()}) { |
+ var body = new Block([new ReturnStatement(new NullLiteral())]); |
+ return new Procedure(new Name(name), ProcedureKind.Getter, |
+ new FunctionNode(body, returnType: returnType)); |
+ } |
+ |
Procedure newEmptyMethod(String name, {bool isAbstract: false}) { |
var body = isAbstract ? null : new Block([]); |
return new Procedure(new Name(name), ProcedureKind.Method, |
@@ -136,14 +143,15 @@ abstract class _ClassHierarchyTest { |
isAbstract: isAbstract); |
} |
- Procedure newEmptySetter(String name, {bool abstract: false}) { |
+ Procedure newEmptySetter(String name, |
+ {bool abstract: false, DartType type: const DynamicType()}) { |
var body = abstract ? null : new Block([]); |
return new Procedure( |
new Name(name), |
ProcedureKind.Setter, |
new FunctionNode(body, |
returnType: const VoidType(), |
- positionalParameters: [new VariableDeclaration('_')])); |
+ positionalParameters: [new VariableDeclaration('_', type: type)])); |
} |
void setUp() { |
@@ -157,6 +165,38 @@ abstract class _ClassHierarchyTest { |
program.libraries.add(library); |
} |
+ void test_forEachOverridePair_crossGetterSetter_super() { |
+ var int = coreTypes.intClass.rawType; |
+ var a = addClass(new Class(name: 'A', supertype: objectSuper, procedures: [ |
+ newEmptySetter('foo', type: int), |
+ newEmptyGetter('bar', returnType: int) |
+ ])); |
+ var b = addClass(new Class( |
+ name: 'B', |
+ supertype: a.asThisSupertype, |
+ procedures: [newEmptyGetter('foo'), newEmptySetter('bar')])); |
+ |
+ _assertTestLibraryText(''' |
+class A { |
+ set foo(core::int _) → void {} |
+ get bar() → core::int { |
+ return null; |
+ } |
+} |
+class B extends self::A { |
+ get foo() → dynamic { |
+ return null; |
+ } |
+ set bar(dynamic _) → void {} |
+} |
+'''); |
+ |
+ _assertOverridePairs(b, [ |
+ 'test::B::foo overrides test::A::foo=', |
+ 'test::B::bar= overrides test::A::bar' |
+ ]); |
Paul Berry
2017/06/16 22:05:11
We should also test that if `crossGettersSetters:
|
+ } |
+ |
/// 2. A non-abstract member is inherited from a superclass, and in the |
/// context of this class, it overrides an abstract member inheritable through |
/// one of its superinterfaces. |
@@ -905,12 +945,14 @@ class B<T> extends self::A<self::B::T, core::bool> {} |
void _assertOverridePairs(Class class_, List<String> expected) { |
List<String> overrideDescriptions = []; |
hierarchy.forEachOverridePair(class_, |
- (Member declaredMember, Member interfaceMember, bool isSetter) { |
- String declaredName = '$declaredMember${isSetter ? '=': ''}'; |
- String interfaceName = '$interfaceMember${isSetter ? '=': ''}'; |
+ (Member declaredMember, Member interfaceMember, bool isSetter_) { |
Paul Berry
2017/06/16 22:05:11
We are no longer checking that forEachOverridePair
scheglov
2017/06/16 23:49:41
Done.
|
+ String declaredSuffix = _isSetter(declaredMember) ? '=' : ''; |
+ String interfaceSuffix = _isSetter(interfaceMember) ? '=' : ''; |
+ String declaredName = '$declaredMember$declaredSuffix'; |
+ String interfaceName = '$interfaceMember$interfaceSuffix'; |
var desc = '$declaredName overrides $interfaceName'; |
overrideDescriptions.add(desc); |
- }); |
+ }, crossGettersSetters: true); |
expect(overrideDescriptions, unorderedEquals(expected)); |
} |
@@ -943,4 +985,8 @@ import "dart:core" as core; |
expect(actualText, expectedText); |
} |
+ |
+ static bool _isSetter(Member member) { |
+ return member is Procedure && member.kind == ProcedureKind.Setter; |
+ } |
} |