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

Side by Side Diff: pkg/compiler/lib/src/typechecker.dart

Issue 2141023002: Make initializing formal access available by default (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Additional clean-up, now ready to land Created 4 years 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library dart2js.typechecker; 5 library dart2js.typechecker;
6 6
7 import 'common/names.dart' show Identifiers; 7 import 'common/names.dart' show Identifiers;
8 import 'common/resolution.dart' show Resolution; 8 import 'common/resolution.dart' show Resolution;
9 import 'common/tasks.dart' show CompilerTask; 9 import 'common/tasks.dart' show CompilerTask;
10 import 'common.dart'; 10 import 'common.dart';
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 if (node.isThis()) { 679 if (node.isThis()) {
680 return thisType; 680 return thisType;
681 } else if (node.isSuper()) { 681 } else if (node.isSuper()) {
682 return superType; 682 return superType;
683 } else { 683 } else {
684 TypedElement element = elements[node]; 684 TypedElement element = elements[node];
685 assert(invariant(node, element != null, 685 assert(invariant(node, element != null,
686 message: 'Missing element for identifier')); 686 message: 'Missing element for identifier'));
687 assert(invariant( 687 assert(invariant(
688 node, 688 node,
689 element.isVariable || 689 element.isVariable || element.isParameter || element.isField,
690 element.isRegularParameter ||
691 element.isField ||
692 (element.isInitializingFormal &&
693 compiler.options.enableInitializingFormalAccess),
694 message: 'Unexpected context element ${element}')); 690 message: 'Unexpected context element ${element}'));
695 return element.computeType(resolution); 691 return element.computeType(resolution);
696 } 692 }
697 } 693 }
698 694
699 DartType visitIf(If node) { 695 DartType visitIf(If node) {
700 Expression condition = node.condition.expression; 696 Expression condition = node.condition.expression;
701 Statement thenPart = node.thenPart; 697 Statement thenPart = node.thenPart;
702 698
703 checkCondition(node.condition); 699 checkCondition(node.condition);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 if (unaliasedBound.treatAsDynamic) { 764 if (unaliasedBound.treatAsDynamic) {
769 return new DynamicAccess(); 765 return new DynamicAccess();
770 } 766 }
771 InterfaceType interface = 767 InterfaceType interface =
772 Types.computeInterfaceType(resolution, unaliasedBound); 768 Types.computeInterfaceType(resolution, unaliasedBound);
773 ElementAccess access = getAccess(memberName, unaliasedBound, interface); 769 ElementAccess access = getAccess(memberName, unaliasedBound, interface);
774 if (access != null) { 770 if (access != null) {
775 return access; 771 return access;
776 } 772 }
777 if (receiverElement != null && 773 if (receiverElement != null &&
778 (receiverElement.isVariable || 774 (receiverElement.isVariable || receiverElement.isParameter)) {
779 receiverElement.isRegularParameter ||
780 (receiverElement.isInitializingFormal &&
781 compiler.options.enableInitializingFormalAccess))) {
782 Link<TypePromotion> typePromotions = typePromotionsMap[receiverElement]; 775 Link<TypePromotion> typePromotions = typePromotionsMap[receiverElement];
783 if (typePromotions != null) { 776 if (typePromotions != null) {
784 while (!typePromotions.isEmpty) { 777 while (!typePromotions.isEmpty) {
785 TypePromotion typePromotion = typePromotions.head; 778 TypePromotion typePromotion = typePromotions.head;
786 if (!typePromotion.isValid) { 779 if (!typePromotion.isValid) {
787 DartType unaliasedBound = 780 DartType unaliasedBound =
788 Types.computeUnaliasedBound(resolution, typePromotion.type); 781 Types.computeUnaliasedBound(resolution, typePromotion.type);
789 if (!unaliasedBound.treatAsDynamic) { 782 if (!unaliasedBound.treatAsDynamic) {
790 InterfaceType interface = 783 InterfaceType interface =
791 Types.computeInterfaceType(resolution, unaliasedBound); 784 Types.computeInterfaceType(resolution, unaliasedBound);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 return null; 1081 return null;
1089 } 1082 }
1090 } 1083 }
1091 1084
1092 ElementAccess createResolvedAccess(Send node, String name, Element element) { 1085 ElementAccess createResolvedAccess(Send node, String name, Element element) {
1093 checkPrivateAccess(node, element, name); 1086 checkPrivateAccess(node, element, name);
1094 return createPromotedAccess(element); 1087 return createPromotedAccess(element);
1095 } 1088 }
1096 1089
1097 ElementAccess createPromotedAccess(Element element) { 1090 ElementAccess createPromotedAccess(Element element) {
1098 if (element.isVariable || 1091 if (element.isVariable || element.isParameter) {
1099 element.isRegularParameter ||
1100 (element.isInitializingFormal &&
1101 compiler.options.enableInitializingFormalAccess)) {
1102 TypePromotion typePromotion = getKnownTypePromotion(element); 1092 TypePromotion typePromotion = getKnownTypePromotion(element);
1103 if (typePromotion != null) { 1093 if (typePromotion != null) {
1104 return new PromotedAccess(element, typePromotion.type); 1094 return new PromotedAccess(element, typePromotion.type);
1105 } 1095 }
1106 } 1096 }
1107 return new ResolvedAccess(element); 1097 return new ResolvedAccess(element);
1108 } 1098 }
1109 1099
1110 /** 1100 /**
1111 * Computes the type of the access of [name] on the [node] possibly using the 1101 * Computes the type of the access of [name] on the [node] possibly using the
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 // Look for the variable element within parenthesized expressions. 1198 // Look for the variable element within parenthesized expressions.
1209 ParenthesizedExpression parentheses = 1199 ParenthesizedExpression parentheses =
1210 node.receiver.asParenthesizedExpression(); 1200 node.receiver.asParenthesizedExpression();
1211 while (parentheses != null) { 1201 while (parentheses != null) {
1212 variable = elements[parentheses.expression]; 1202 variable = elements[parentheses.expression];
1213 if (variable != null) break; 1203 if (variable != null) break;
1214 parentheses = parentheses.expression.asParenthesizedExpression(); 1204 parentheses = parentheses.expression.asParenthesizedExpression();
1215 } 1205 }
1216 } 1206 }
1217 1207
1218 if (variable != null && 1208 if (variable != null && (variable.isVariable || variable.isParameter)) {
1219 (variable.isVariable ||
1220 variable.isRegularParameter ||
1221 (variable.isInitializingFormal &&
1222 compiler.options.enableInitializingFormalAccess))) {
1223 DartType knownType = getKnownType(variable); 1209 DartType knownType = getKnownType(variable);
1224 if (!knownType.isDynamic) { 1210 if (!knownType.isDynamic) {
1225 DartType shownType = elements.getType(node.arguments.head); 1211 DartType shownType = elements.getType(node.arguments.head);
1226 TypePromotion typePromotion = 1212 TypePromotion typePromotion =
1227 new TypePromotion(node, variable, shownType); 1213 new TypePromotion(node, variable, shownType);
1228 if (!types.isMoreSpecific(shownType, knownType)) { 1214 if (!types.isMoreSpecific(shownType, knownType)) {
1229 String variableName = variable.name; 1215 String variableName = variable.name;
1230 if (!types.isSubtype(shownType, knownType)) { 1216 if (!types.isSubtype(shownType, knownType)) {
1231 typePromotion.addHint(reporter.createMessage( 1217 typePromotion.addHint(reporter.createMessage(
1232 node, MessageKind.NOT_MORE_SPECIFIC_SUBTYPE, { 1218 node, MessageKind.NOT_MORE_SPECIFIC_SUBTYPE, {
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 2033
2048 visitTypedef(Typedef node) { 2034 visitTypedef(Typedef node) {
2049 // Do not typecheck [Typedef] nodes. 2035 // Do not typecheck [Typedef] nodes.
2050 } 2036 }
2051 2037
2052 visitNode(Node node) { 2038 visitNode(Node node) {
2053 reporter.internalError(node, 2039 reporter.internalError(node,
2054 'Unexpected node ${node.getObjectDescription()} in the type checker.'); 2040 'Unexpected node ${node.getObjectDescription()} in the type checker.');
2055 } 2041 }
2056 } 2042 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution.dart ('k') | tests/isolate/compile_time_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698