Skip to content

Commit

Permalink
Allow super invocations find members in supertypes of old style mixins.
Browse files Browse the repository at this point in the history
We should delete this code once Flutter switches to the new mixins.

R=brianwilkerson@google.com

Change-Id: Ib57d9093dade0d926386647f47f91918e92a51f2
Reviewed-on: https://dart-review.googlesource.com/76700
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Sep 26, 2018
1 parent a0ff5f8 commit 4dcd839
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 17 additions & 5 deletions pkg/analyzer/lib/src/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {

ExecutableElement lookUpInheritedMember(String name, LibraryElement library,
{bool concrete: false,
bool forSuperInvocation: false,
int startMixinIndex,
bool setter: false,
bool thisType: false}) {
Expand All @@ -1832,7 +1833,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
ExecutableElement lookUpImpl(InterfaceTypeImpl type,
{bool acceptAbstract: false,
bool includeType: true,
bool includeSupers: true,
bool inMixin: false,
int startMixinIndex}) {
if (type == null || !visitedClasses.add(type.element)) {
return null;
Expand All @@ -1853,14 +1854,24 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
}

if (includeSupers) {
if (forSuperInvocation) {
bool inOldStyleSuperMixin = inMixin &&
type.superclass != null &&
!type.superclass.isObject &&
element.context.analysisOptions.enableSuperMixins;
if (inOldStyleSuperMixin) {
acceptAbstract = true;
}
}

if (!inMixin || acceptAbstract) {
var mixins = type.mixins;
startMixinIndex ??= mixins.length;
for (var i = startMixinIndex - 1; i >= 0; i--) {
var result = lookUpImpl(
mixins[i],
acceptAbstract: acceptAbstract,
includeSupers: false,
inMixin: true,
);
if (result != null) {
return result;
Expand All @@ -1879,8 +1890,9 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
}

if (includeSupers) {
return lookUpImpl(type.superclass, acceptAbstract: acceptAbstract);
if (!inMixin || acceptAbstract) {
return lookUpImpl(type.superclass,
acceptAbstract: acceptAbstract, inMixin: inMixin);
}

return null;
Expand Down
6 changes: 4 additions & 2 deletions pkg/analyzer/lib/src/generated/element_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
if (staticType is InterfaceTypeImpl) {
staticElement = staticType.lookUpInheritedMember(
methodName.name, _definingLibrary,
concrete: true);
concrete: true, forSuperInvocation: true);
// We were not able to find the concrete dispatch target.
// But we would like to give the user at least some resolution.
// So, we retry without the "concrete" requirement.
Expand Down Expand Up @@ -2096,7 +2096,9 @@ class ElementResolver extends SimpleAstVisitor<Object> {
if (staticType is InterfaceTypeImpl) {
staticElement = staticType.lookUpInheritedMember(
propertyName.name, _definingLibrary,
setter: propertyName.inSetterContext(), concrete: true);
setter: propertyName.inSetterContext(),
concrete: true,
forSuperInvocation: true);
// We were not able to find the concrete dispatch target.
// But we would like to give the user at least some resolution.
// So, we retry without the "concrete" requirement.
Expand Down

0 comments on commit 4dcd839

Please sign in to comment.