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

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

Issue 1852883003: Fix summarizing of types with unused type parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 buildingLinkedReferences = true; 443 buildingLinkedReferences = true;
444 linkedUnit.types = deferredLinkedTypes 444 linkedUnit.types = deferredLinkedTypes
445 .map((_SerializeTypeRef closure) => closure()) 445 .map((_SerializeTypeRef closure) => closure())
446 .toList(); 446 .toList();
447 linkedUnit.constCycles = constCycles; 447 linkedUnit.constCycles = constCycles;
448 buildingLinkedReferences = false; 448 buildingLinkedReferences = false;
449 } 449 }
450 450
451 /** 451 /**
452 * Compute the appropriate De Bruijn index to represent the given type 452 * Compute the appropriate De Bruijn index to represent the given type
453 * parameter [type]. 453 * parameter [type], or return `null` if the type parameter is not in scope.
454 */ 454 */
455 int findTypeParameterIndex(TypeParameterType type, Element context) { 455 int findTypeParameterIndex(TypeParameterType type, Element context) {
456 Element originalContext = context; 456 Element originalContext = context;
457 int index = 0; 457 int index = 0;
458 while (context != null) { 458 while (context != null) {
459 List<TypeParameterElement> typeParameters; 459 List<TypeParameterElement> typeParameters;
460 if (context is ClassElement) { 460 if (context is ClassElement) {
461 typeParameters = context.typeParameters; 461 typeParameters = context.typeParameters;
462 } else if (context is FunctionTypeAliasElement) { 462 } else if (context is FunctionTypeAliasElement) {
463 typeParameters = context.typeParameters; 463 typeParameters = context.typeParameters;
464 } else if (context is ExecutableElement) { 464 } else if (context is ExecutableElement) {
465 typeParameters = context.typeParameters; 465 typeParameters = context.typeParameters;
466 } 466 }
467 if (typeParameters != null) { 467 if (typeParameters != null) {
468 for (int i = 0; i < typeParameters.length; i++) { 468 for (int i = 0; i < typeParameters.length; i++) {
469 TypeParameterElement param = typeParameters[i]; 469 TypeParameterElement param = typeParameters[i];
470 if (param == type.element) { 470 if (param == type.element) {
471 return index + typeParameters.length - i; 471 return index + typeParameters.length - i;
472 } 472 }
473 } 473 }
474 index += typeParameters.length; 474 index += typeParameters.length;
475 } 475 }
476 context = context.enclosingElement; 476 context = context.enclosingElement;
477 } 477 }
478 throw new StateError( 478 return null;
479 'Unbound type parameter $type (${originalContext?.location})');
480 } 479 }
481 480
482 /** 481 /**
483 * Get the type arguments for the given [type], or `null` if the type has no 482 * Get the type arguments for the given [type], or `null` if the type has no
484 * type arguments. 483 * type arguments.
485 * 484 *
486 * TODO(paulberry): consider adding an abstract getter to [DartType] to do 485 * TODO(paulberry): consider adding an abstract getter to [DartType] to do
487 * this. 486 * this.
488 */ 487 */
489 List<DartType> getTypeArguments(DartType type) { 488 List<DartType> getTypeArguments(DartType type) {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 * interpreted; this is used to serialize type parameters. 1001 * interpreted; this is used to serialize type parameters.
1003 */ 1002 */
1004 EntityRefBuilder serializeTypeRef(DartType type, Element context, 1003 EntityRefBuilder serializeTypeRef(DartType type, Element context,
1005 {int slot}) { 1004 {int slot}) {
1006 if (slot != null) { 1005 if (slot != null) {
1007 assert(buildingLinkedReferences); 1006 assert(buildingLinkedReferences);
1008 } 1007 }
1009 EntityRefBuilder b = new EntityRefBuilder(slot: slot); 1008 EntityRefBuilder b = new EntityRefBuilder(slot: slot);
1010 Element typeElement = type.element; 1009 Element typeElement = type.element;
1011 if (type is TypeParameterType) { 1010 if (type is TypeParameterType) {
1012 b.paramReference = findTypeParameterIndex(type, context); 1011 int typeParameterIndex = findTypeParameterIndex(type, context);
1012 if (typeParameterIndex != null) {
1013 b.paramReference = typeParameterIndex;
1014 } else {
1015 // Out-of-scope type parameters only occur in circumstances where they
1016 // are irrelevant (i.e. when a type parameter is unused). So we can
1017 // safely convert them to `dynamic`.
1018 b.reference = serializeReferenceForType(DynamicTypeImpl.instance);
1019 }
1013 } else if (type is FunctionType && 1020 } else if (type is FunctionType &&
1014 typeElement is FunctionElement && 1021 typeElement is FunctionElement &&
1015 typeElement.enclosingElement == null) { 1022 typeElement.enclosingElement == null) {
1016 b.syntheticReturnType = 1023 b.syntheticReturnType =
1017 serializeTypeRef(typeElement.returnType, typeElement); 1024 serializeTypeRef(typeElement.returnType, typeElement);
1018 b.syntheticParams = typeElement.parameters 1025 b.syntheticParams = typeElement.parameters
1019 .map((ParameterElement param) => serializeParam(param, context)) 1026 .map((ParameterElement param) => serializeParam(param, context))
1020 .toList(); 1027 .toList();
1021 } else { 1028 } else {
1022 if (type is FunctionType && 1029 if (type is FunctionType &&
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 exportNames.add(new LinkedExportNameBuilder( 1629 exportNames.add(new LinkedExportNameBuilder(
1623 name: name, 1630 name: name,
1624 dependency: serializeDependency(dependentLibrary), 1631 dependency: serializeDependency(dependentLibrary),
1625 unit: unit, 1632 unit: unit,
1626 kind: kind)); 1633 kind: kind));
1627 } 1634 }
1628 pb.exportNames = exportNames; 1635 pb.exportNames = exportNames;
1629 return pb; 1636 return pb;
1630 } 1637 }
1631 } 1638 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698