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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1950333003: Fix a corner case of inferred types with function-typed parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Also test resynthesis. Created 4 years, 7 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 serialization.elements; 5 library serialization.elements;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 for (MethodElement method in cls.methods) { 610 for (MethodElement method in cls.methods) {
611 if (method.isStatic && method.isPublic) { 611 if (method.isStatic && method.isPublic) {
612 // TODO(paulberry): should numTypeParameters include class params? 612 // TODO(paulberry): should numTypeParameters include class params?
613 bs.add(new UnlinkedPublicNameBuilder( 613 bs.add(new UnlinkedPublicNameBuilder(
614 name: method.name, 614 name: method.name,
615 kind: ReferenceKind.method, 615 kind: ReferenceKind.method,
616 numTypeParameters: method.typeParameters.length)); 616 numTypeParameters: method.typeParameters.length));
617 } 617 }
618 } 618 }
619 for (PropertyAccessorElement accessor in cls.accessors) { 619 for (PropertyAccessorElement accessor in cls.accessors) {
620 if (accessor.isStatic && 620 if (accessor.isStatic && accessor.isGetter && accessor.isPublic) {
621 accessor.isGetter &&
622 accessor.isPublic) {
623 // TODO(paulberry): should numTypeParameters include class params? 621 // TODO(paulberry): should numTypeParameters include class params?
624 bs.add(new UnlinkedPublicNameBuilder( 622 bs.add(new UnlinkedPublicNameBuilder(
625 name: accessor.name, kind: ReferenceKind.propertyAccessor)); 623 name: accessor.name, kind: ReferenceKind.propertyAccessor));
626 } 624 }
627 } 625 }
628 for (ConstructorElement constructor in cls.constructors) { 626 for (ConstructorElement constructor in cls.constructors) {
629 if (constructor.isPublic && constructor.name.isNotEmpty) { 627 if (constructor.isPublic && constructor.name.isNotEmpty) {
630 // TODO(paulberry): should numTypeParameters include class params? 628 // TODO(paulberry): should numTypeParameters include class params?
631 bs.add(new UnlinkedPublicNameBuilder( 629 bs.add(new UnlinkedPublicNameBuilder(
632 name: constructor.name, 630 name: constructor.name,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 } else { 1042 } else {
1045 if (type is FunctionType && 1043 if (type is FunctionType &&
1046 typeElement.enclosingElement is ParameterElement) { 1044 typeElement.enclosingElement is ParameterElement) {
1047 // Code cannot refer to function types implicitly defined by parameters 1045 // Code cannot refer to function types implicitly defined by parameters
1048 // directly, so if we get here, we must be serializing a linked 1046 // directly, so if we get here, we must be serializing a linked
1049 // reference from type inference. 1047 // reference from type inference.
1050 assert(buildingLinkedReferences); 1048 assert(buildingLinkedReferences);
1051 ParameterElement parameterElement = typeElement.enclosingElement; 1049 ParameterElement parameterElement = typeElement.enclosingElement;
1052 while (true) { 1050 while (true) {
1053 Element parent = parameterElement.enclosingElement; 1051 Element parent = parameterElement.enclosingElement;
1054 if (parent is FunctionTypedElement) { 1052 if (parent is ParameterElement) {
1055 Element grandParent = parent.enclosingElement; 1053 // Function-typed parameter inside a function-typed parameter.
1056 b.implicitFunctionTypeIndices 1054 b.implicitFunctionTypeIndices
1057 .insert(0, parent.parameters.indexOf(parameterElement)); 1055 .insert(0, parent.parameters.indexOf(parameterElement));
1058 if (grandParent is ParameterElement) { 1056 parameterElement = parent;
1059 // Function-typed parameter inside a function-typed parameter. 1057 continue;
1060 parameterElement = grandParent; 1058 } else if (parent is FunctionTypedElement) {
1061 continue; 1059 b.implicitFunctionTypeIndices
1062 } else { 1060 .insert(0, parent.parameters.indexOf(parameterElement));
1063 // Function-typed parameter inside a top level function or method. 1061 // Function-typed parameter inside a top level function, method, or
1064 b.reference = _getElementReferenceId(parent); 1062 // typedef.
1065 break; 1063 b.reference = _getElementReferenceId(parent);
1066 } 1064 break;
1067 } else { 1065 } else {
1068 throw new StateError( 1066 throw new StateError(
1069 'Unexpected element enclosing parameter: ${parent.runtimeType}') ; 1067 'Unexpected element enclosing parameter: ${parent.runtimeType}') ;
1070 } 1068 }
1071 } 1069 }
1072 } else { 1070 } else {
1073 b.reference = serializeReferenceForType(type); 1071 b.reference = serializeReferenceForType(type);
1074 } 1072 }
1075 List<DartType> typeArguments = getTypeArguments(type); 1073 List<DartType> typeArguments = getTypeArguments(type);
1076 if (typeArguments != null) { 1074 if (typeArguments != null) {
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 exportNames.add(new LinkedExportNameBuilder( 1666 exportNames.add(new LinkedExportNameBuilder(
1669 name: name, 1667 name: name,
1670 dependency: serializeDependency(dependentLibrary), 1668 dependency: serializeDependency(dependentLibrary),
1671 unit: unit, 1669 unit: unit,
1672 kind: kind)); 1670 kind: kind));
1673 } 1671 }
1674 pb.exportNames = exportNames; 1672 pb.exportNames = exportNames;
1675 return pb; 1673 return pb;
1676 } 1674 }
1677 } 1675 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698