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

Side by Side Diff: pkg/kernel/test/class_hierarchy_test.dart

Issue 2946733003: Fix type inference of getters that "override" setters and vice versa. (Closed)
Patch Set: Address code review comments Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:kernel/ast.dart'; 5 import 'package:kernel/ast.dart';
6 import 'package:kernel/class_hierarchy.dart'; 6 import 'package:kernel/class_hierarchy.dart';
7 import 'package:kernel/core_types.dart'; 7 import 'package:kernel/core_types.dart';
8 import 'package:kernel/src/incremental_class_hierarchy.dart'; 8 import 'package:kernel/src/incremental_class_hierarchy.dart';
9 import 'package:kernel/testing/mock_sdk_program.dart'; 9 import 'package:kernel/testing/mock_sdk_program.dart';
10 import 'package:kernel/text/ast_to_text.dart'; 10 import 'package:kernel/text/ast_to_text.dart';
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 var b_int = new InterfaceType(b, [int]); 988 var b_int = new InterfaceType(b, [int]);
989 expect(hierarchy.getTypeAsInstanceOf(b_int, a), 989 expect(hierarchy.getTypeAsInstanceOf(b_int, a),
990 new InterfaceType(a, [int, bool])); 990 new InterfaceType(a, [int, bool]));
991 expect(hierarchy.getTypeAsInstanceOf(b_int, objectClass), 991 expect(hierarchy.getTypeAsInstanceOf(b_int, objectClass),
992 new InterfaceType(objectClass)); 992 new InterfaceType(objectClass));
993 } 993 }
994 994
995 void _assertOverridePairs(Class class_, List<String> expected, 995 void _assertOverridePairs(Class class_, List<String> expected,
996 {bool crossGettersSetters: false}) { 996 {bool crossGettersSetters: false}) {
997 List<String> overrideDescriptions = []; 997 List<String> overrideDescriptions = [];
998 hierarchy.forEachOverridePair(class_, 998 void callback(
999 (Member declaredMember, Member interfaceMember, bool isSetter) { 999 Member declaredMember, Member interfaceMember, bool isSetter) {
1000 String declaredSuffix; 1000 String declaredSuffix;
1001 String interfaceSuffix; 1001 String interfaceSuffix;
1002 declaredSuffix = isSetter ? '=' : '';
1002 if (crossGettersSetters) { 1003 if (crossGettersSetters) {
1003 declaredSuffix = _isSetter(declaredMember) ? '=' : ''; 1004 interfaceSuffix = isSetter ? '' : '=';
1004 interfaceSuffix = _isSetter(interfaceMember) ? '=' : '';
1005 } else { 1005 } else {
1006 declaredSuffix = isSetter ? '=' : '';
1007 interfaceSuffix = isSetter ? '=' : ''; 1006 interfaceSuffix = isSetter ? '=' : '';
1008 } 1007 }
1009 String declaredName = '$declaredMember$declaredSuffix'; 1008 String declaredName = '$declaredMember$declaredSuffix';
1010 String interfaceName = '$interfaceMember$interfaceSuffix'; 1009 String interfaceName = '$interfaceMember$interfaceSuffix';
1011 var desc = '$declaredName overrides $interfaceName'; 1010 var desc = '$declaredName overrides $interfaceName';
1012 overrideDescriptions.add(desc); 1011 overrideDescriptions.add(desc);
1013 }, crossGettersSetters: crossGettersSetters); 1012 }
1013
1014 if (crossGettersSetters) {
1015 hierarchy.forEachCrossOverridePair(class_, callback);
1016 } else {
1017 hierarchy.forEachOverridePair(class_, callback);
1018 }
1014 expect(overrideDescriptions, unorderedEquals(expected)); 1019 expect(overrideDescriptions, unorderedEquals(expected));
1015 } 1020 }
1016 1021
1017 /// Assert that the test [library] has the [expectedText] presentation. 1022 /// Assert that the test [library] has the [expectedText] presentation.
1018 /// The presentation is close, but not identical to the normal Kernel one. 1023 /// The presentation is close, but not identical to the normal Kernel one.
1019 void _assertTestLibraryText(String expectedText) { 1024 void _assertTestLibraryText(String expectedText) {
1020 StringBuffer sb = new StringBuffer(); 1025 StringBuffer sb = new StringBuffer();
1021 Printer printer = new Printer(sb); 1026 Printer printer = new Printer(sb);
1022 printer.writeLibraryFile(library); 1027 printer.writeLibraryFile(library);
1023 1028
(...skipping 12 matching lines...) Expand all
1036 actualText = actualText.replaceAll('{\n}', '{}'); 1041 actualText = actualText.replaceAll('{\n}', '{}');
1037 actualText = actualText.replaceAll(' extends core::Object', ''); 1042 actualText = actualText.replaceAll(' extends core::Object', '');
1038 1043
1039 if (actualText != expectedText) { 1044 if (actualText != expectedText) {
1040 print('-------- Actual --------'); 1045 print('-------- Actual --------');
1041 print(actualText + '------------------------'); 1046 print(actualText + '------------------------');
1042 } 1047 }
1043 1048
1044 expect(actualText, expectedText); 1049 expect(actualText, expectedText);
1045 } 1050 }
1046
1047 static bool _isSetter(Member member) {
1048 return member is Procedure && member.kind == ProcedureKind.Setter;
1049 }
1050 } 1051 }
OLDNEW
« pkg/kernel/lib/class_hierarchy.dart ('K') | « pkg/kernel/lib/src/incremental_class_hierarchy.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698