Skip to content

Commit

Permalink
Version 3.3.0-124.0.dev
Browse files Browse the repository at this point in the history
Merge 57a2fb6 into dev
  • Loading branch information
Dart CI committed Nov 13, 2023
2 parents 1a1b9cb + 57a2fb6 commit 95da64a
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ abstract class AugmentedInterfaceElementImpl

@override
// TODO: implement declaration
InterfaceElement get declaration => throw UnimplementedError();
InterfaceElementImpl get declaration => throw UnimplementedError();

@override
// TODO: implement unnamedConstructor
Expand Down
6 changes: 5 additions & 1 deletion pkg/analyzer/lib/src/dart/element/type_algebra.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ abstract class Substitution {

DartType? getSubstitute(TypeParameterElement parameter, bool upperBound);

InterfaceType mapInterfaceType(InterfaceType type) {
return substituteType(type) as InterfaceType;
}

Iterable<InterfaceType> mapInterfaceTypes(Iterable<InterfaceType> types) {
return types.map(substituteType).whereType();
return types.map(mapInterfaceType);
}

DartType substituteType(DartType type, {bool contravariant = false}) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,35 @@ class LibraryBuilder {
}
}

void setDefaultSupertypes() {
var shouldResetClassHierarchies = false;
final objectType = element.typeProvider.objectType;
for (final interface in element.topLevelElements) {
switch (interface) {
case ClassElementImpl():
if (interface.isAugmentation) continue;
if (interface.isDartCoreObject) continue;
if (interface.supertype == null) {
shouldResetClassHierarchies = true;
interface.supertype = objectType;
}
case MixinElementImpl():
if (interface.isAugmentation) continue;
final augmented = interface.augmented!;
if (augmented.superclassConstraints.isEmpty) {
shouldResetClassHierarchies = true;
interface.superclassConstraints = [objectType];
if (augmented is AugmentedMixinElementImpl) {
augmented.superclassConstraints = [objectType];
}
}
}
}
if (shouldResetClassHierarchies) {
element.session.classHierarchy.removeOfLibraries({uri});
}
}

void storeExportScope() {
element.exportedReferences = exportScope.toReferences();

Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/summary2/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Linker {

_createTypeSystem();
_resolveTypes();
_setDefaultSupertypes();

await performance.runAsync(
'executeMacroDeclarationsPhase',
Expand Down Expand Up @@ -374,6 +375,12 @@ class Linker {
TypesBuilder(this).build(nodesToBuildType);
}

void _setDefaultSupertypes() {
for (final library in builders.values) {
library.setDefaultSupertypes();
}
}

void _writeLibraries() {
var bundleWriter = BundleWriter(
elementFactory.dynamicRef,
Expand Down
26 changes: 11 additions & 15 deletions pkg/analyzer/lib/src/summary2/types_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,9 @@ class TypesBuilder {
var type = extendsClause.superclass.type;
if (type is InterfaceType && _isInterfaceTypeClass(type)) {
element.supertype = type;
} else {
element.supertype = _objectType(element);
}
} else if (element.library.isDartCore && element.name == 'Object') {
} else if (element.isDartCoreObject) {
element.setModifier(Modifier.DART_CORE_OBJECT, true);
} else {
element.supertype = _objectType(element);
}

element.interfaces = _toInterfaceTypeList(
Expand All @@ -158,8 +154,6 @@ class TypesBuilder {
var superType = node.superclass.type;
if (superType is InterfaceType && _isInterfaceTypeClass(superType)) {
element.supertype = superType;
} else {
element.supertype = _objectType(element);
}

element.mixins = _toInterfaceTypeList(
Expand Down Expand Up @@ -346,9 +340,6 @@ class TypesBuilder {
var constraints = _toInterfaceTypeList(
node.onClause?.superclassConstraints,
);
if (!element.isAugmentation && constraints.isEmpty) {
constraints = [_objectType(element)];
}
element.superclassConstraints = constraints;

element.interfaces = _toInterfaceTypeList(
Expand Down Expand Up @@ -449,7 +440,16 @@ class TypesBuilder {
final typeProvider = element.library.typeProvider;

if (element is InterfaceElementImpl &&
augmented is AugmentedInterfaceElementImpl) {
augmented is AugmentedInterfaceElementImpl &&
declaration is InterfaceElementImpl) {
if (declaration.supertype == null) {
final elementSuperType = element.supertype;
if (elementSuperType != null) {
final superType = toDeclaration.mapInterfaceType(elementSuperType);
declaration.supertype = superType;
}
}

augmented.interfaces.addAll(
toDeclaration.mapInterfaceTypes(element.interfaces),
);
Expand Down Expand Up @@ -509,10 +509,6 @@ class TypesBuilder {
nullabilitySuffix: NullabilitySuffix.none,
);
}

static InterfaceType _objectType(InterfaceElementImpl element) {
return element.library.typeProvider.objectType;
}
}

/// Performs mixins inference in a [ClassDeclaration].
Expand Down
14 changes: 7 additions & 7 deletions pkg/analyzer/test/src/summary/element_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ String getLibraryText({

class ElementTextConfiguration {
bool Function(Object) filter;
bool withAllSupertypes = false;
bool withAugmentedWithoutAugmentation = false;
bool withCodeRanges = false;
bool withConstantInitializers = true;
Expand Down Expand Up @@ -637,21 +638,20 @@ class _ElementWriter {
}

if (e is MixinElementImpl) {
final superclassConstraints = e.superclassConstraints;
if (!e.isAugmentation) {
if (superclassConstraints.isEmpty) {
throw StateError('At least Object is expected.');
}
}
_elementPrinter.writeTypeList(
'superclassConstraints',
superclassConstraints,
e.superclassConstraints,
);
}

_elementPrinter.writeTypeList('mixins', e.mixins);
_elementPrinter.writeTypeList('interfaces', e.interfaces);

if (configuration.withAllSupertypes) {
final sorted = e.allSupertypes.sortedBy((t) => t.element.name);
_elementPrinter.writeTypeList('allSupertypes', sorted);
}

_writeElements('fields', e.fields, _writePropertyInducingElement);

var constructors = e.constructors;
Expand Down
Loading

0 comments on commit 95da64a

Please sign in to comment.