Skip to content

Commit

Permalink
Version 3.1.0-324.0.dev
Browse files Browse the repository at this point in the history
Merge f06a1d5 into dev
  • Loading branch information
Dart CI committed Jul 18, 2023
2 parents ec95774 + f06a1d5 commit c184cac
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 88 deletions.
11 changes: 3 additions & 8 deletions pkg/analyzer/lib/src/dart/element/class_hierarchy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/extensions.dart';
import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/utilities/extensions/collection.dart';
Expand All @@ -21,6 +22,7 @@ class ClassHierarchy {
}

void remove(InterfaceElement element) {
assert(!element.isAugmentation);
_map.remove(element);
}

Expand All @@ -32,14 +34,7 @@ class ClassHierarchy {
}

_Hierarchy _getHierarchy(InterfaceElement element) {
if (element.isAugmentation) {
throw StateError('Expected a declaration, not augmentations.');
}

final augmented = element.augmented;
if (augmented == null) {
throw StateError('Declarations always have augmented state.');
}
final augmented = element.augmentedOfDeclaration;

var hierarchy = _map[element];
if (hierarchy != null) {
Expand Down
16 changes: 14 additions & 2 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2615,9 +2615,9 @@ class EnumElementImpl extends InterfaceElementImpl implements EnumElement {
EnumElementImpl(super.name, super.offset);

@override
Never get augmentation {
EnumElementImpl? get augmentation {
// TODO(scheglov) implement
throw UnimplementedError();
return null;
}

@override
Expand Down Expand Up @@ -3521,6 +3521,9 @@ abstract class InterfaceElementImpl extends NamedInstanceElementImpl
return library.session.classHierarchy.implementedInterfaces(this);
}

@override
InterfaceElementImpl? get augmentation;

@override
InterfaceElementImpl? get augmentationTarget;

Expand Down Expand Up @@ -3633,6 +3636,15 @@ abstract class InterfaceElementImpl extends NamedInstanceElementImpl
_typeParameterElements = typeParameters;
}

/// This element and all its augmentations, in order.
Iterable<InterfaceElementImpl> get withAugmentations sync* {
InterfaceElementImpl? current = this;
while (current != null) {
yield current;
current = current.augmentation;
}
}

@override
FieldElement? getField(String name) {
return fields.firstWhereOrNull((fieldElement) => name == fieldElement.name);
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/lib/src/dart/element/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ extension ExecutableElementExtensionQuestion on ExecutableElement? {
}
}

extension InterfaceElementExtension on InterfaceElement {
/// The result of applying augmentations.
///
/// The target must be a declaration, not an augmentation.
/// This getter will throw, if this is not the case.
AugmentedInterfaceElement get augmentedOfDeclaration {
if (isAugmentation) {
throw StateError(
'The target must be a declaration, not an augmentation.',
);
}
// This is safe because declarations always have it.
return augmented!;
}
}

extension ParameterElementExtensions on ParameterElement {
/// Return [ParameterElement] with the specified properties replaced.
ParameterElement copyWith({
Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/lib/src/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
required this.nullabilitySuffix,
super.alias,
}) {
if (element.isAugmentation) {
throw ArgumentError(
'InterfaceType(s) can only be created for declarations',
);
}
var typeParameters = element.typeParameters;
if (typeArguments.length != typeParameters.length) {
throw ArgumentError(
Expand Down
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/summary2/detach_nodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class _Visitor extends GeneralizingElementVisitor<void> {
super.visitElement(element);
}

@override
void visitEnumElement(EnumElement element) {
if (element is EnumElementImpl) {
element.mixinInferenceCallback = null;
}
super.visitEnumElement(element);
}

@override
void visitMixinElement(MixinElement element) {
if (element is MixinElementImpl) {
Expand Down
Loading

0 comments on commit c184cac

Please sign in to comment.