Skip to content

Commit

Permalink
[cfe] Ensure that getDispatchTargetKernel returns a concrete member
Browse files Browse the repository at this point in the history
In response to #43988

Change-Id: I3aa73a073b275b634b679bebfa2bf2ed9c292074
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170087
Reviewed-by: Jens Johansen <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>
  • Loading branch information
johnniwinther authored and [email protected] committed Nov 3, 2020
1 parent 5278383 commit 3f7ca42
Show file tree
Hide file tree
Showing 13 changed files with 733 additions and 28 deletions.
14 changes: 11 additions & 3 deletions pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,17 @@ class ClassHierarchyBuilder implements ClassHierarchyBase {
}

Member getDispatchTargetKernel(Class cls, Name name, bool isSetter) {
return getNodeFromClass(cls)
.getDispatchTarget(name, isSetter)
?.getMember(this);
ClassMember classMember =
getNodeFromClass(cls).getDispatchTarget(name, isSetter);
Member member = classMember?.getMember(this);
if (member != null && member.isAbstract) {
if (cls.superclass != null) {
return getDispatchTargetKernel(cls.superclass, name, isSetter);
} else {
return null;
}
}
return member;
}

Member getCombinedMemberSignatureKernel(Class cls, Name name, bool isSetter,
Expand Down
6 changes: 6 additions & 0 deletions pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class ForwardingNode {
Arguments arguments = new Arguments(positionalArguments,
types: typeArguments, named: namedArguments);
Expression superCall;
assert(superTarget != null,
"No super target found for '${name}' in ${enclosingClass}.");
assert(
!superTarget.isAbstract,
"Abstract super target $superTarget found for '${name}' in "
"${enclosingClass}.");
switch (kind) {
case ProcedureKind.Method:
case ProcedureKind.Operator:
Expand Down
123 changes: 100 additions & 23 deletions pkg/front_end/lib/src/fasta/kernel/member_covariance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,25 @@ class Covariance {
/// If no type parameters are generic-covariant-impl, this is `null`.
final List<bool> _typeParameters;

const Covariance.internal(
this._positionalParameters, this._namedParameters, this._typeParameters);
Covariance.internal(
this._positionalParameters, this._namedParameters, this._typeParameters) {
assert(_positionalParameters == null ||
_positionalParameters.any((element) => element != 0));
assert(_namedParameters == null ||
_namedParameters.values.isNotEmpty &&
_namedParameters.values.every((element) => element != 0));
assert(
_typeParameters == null || _typeParameters.any((element) => element));
}

/// The empty covariance.
///
/// This is used for all members that do not use any covariance, regardless
/// of parameter structure.
const Covariance.empty() : this.internal(null, null, null);
const Covariance.empty()
: _positionalParameters = null,
_namedParameters = null,
_typeParameters = null;

/// Computes the covariance for the setter aspect of [field].
///
Expand Down Expand Up @@ -287,7 +298,7 @@ class Covariance {
int hash = 0;
if (_positionalParameters != null) {
for (int covariance in _positionalParameters) {
hash = hash * 13 + covariance.hashCode * 17;
hash += covariance.hashCode * 17;
}
}
if (_namedParameters != null) {
Expand All @@ -297,7 +308,9 @@ class Covariance {
}
if (_typeParameters != null) {
for (bool covariance in _typeParameters) {
hash = hash * 29 + covariance.hashCode * 31;
if (covariance) {
hash += covariance.hashCode * 31;
}
}
}
return hash;
Expand All @@ -312,12 +325,10 @@ class Covariance {
other._positionalParameters == null) {
return false;
}
if (_positionalParameters.length !=
other._positionalParameters.length) {
return false;
}
for (int i = 0; i < _positionalParameters.length; i++) {
if (_positionalParameters[i] != other._positionalParameters[i]) {
int positionalParameterCount = max(
_positionalParameters.length, other._positionalParameters.length);
for (int i = 0; i < positionalParameterCount; i++) {
if (getPositionalVariance(i) != other.getPositionalVariance(i)) {
return false;
}
}
Expand All @@ -326,13 +337,12 @@ class Covariance {
if (_namedParameters == null || other._namedParameters == null) {
return false;
}
if (_namedParameters.length != other._namedParameters.length) {
return false;
}
for (String name in _namedParameters.keys) {
int covariance = _namedParameters[name];
int otherCovariance = other._namedParameters[name];
if (covariance != otherCovariance) {
Set<String> names = {
..._namedParameters.keys,
...other._namedParameters.keys
};
for (String name in names) {
if (getNamedVariance(name) != other.getNamedVariance(name)) {
return false;
}
}
Expand All @@ -341,11 +351,11 @@ class Covariance {
if (_typeParameters == null || other._typeParameters == null) {
return false;
}
if (_typeParameters.length != other._typeParameters.length) {
return false;
}
for (int i = 0; i < _typeParameters.length; i++) {
if (_typeParameters[i] != other._typeParameters[i]) {
int typeParameterCount =
max(_typeParameters.length, other._typeParameters.length);
for (int i = 0; i < typeParameterCount; i++) {
if (isTypeParameterGenericCovariantImpl(i) !=
other.isTypeParameterGenericCovariantImpl(i)) {
return false;
}
}
Expand All @@ -354,4 +364,71 @@ class Covariance {
}
return false;
}

@override
String toString() {
StringBuffer sb = new StringBuffer();
if (isEmpty) {
sb.write('Covariance.empty()');
} else {
sb.write('Covariance(');
String comma = '';
if (_positionalParameters != null) {
for (int index = 0; index < _positionalParameters.length; index++) {
if (_positionalParameters[index] != 0) {
sb.write(comma);
sb.write('$index:');
switch (_positionalParameters[index]) {
case GenericCovariantImpl:
sb.write('GenericCovariantImpl');
break;
case Covariant:
sb.write('Covariant');
break;
default:
sb.write('GenericCovariantImpl+Covariant');
break;
}
comma = ',';
}
}
}
if (_namedParameters != null) {
for (String name in _namedParameters.keys) {
int covariance = _namedParameters[name];
if (covariance != 0) {
sb.write(comma);
sb.write('$name:');

switch (covariance) {
case GenericCovariantImpl:
sb.write('GenericCovariantImpl');
break;
case Covariant:
sb.write('Covariant');
break;
default:
sb.write('GenericCovariantImpl+Covariant');
break;
}
comma = ',';
}
}
}
if (_typeParameters != null) {
sb.write(comma);
sb.write('types:');
comma = '';
for (int index = 0; index < _typeParameters.length; index++) {
if (_typeParameters[index]) {
sb.write(comma);
sb.write('$index');
comma = ',';
}
}
}
sb.write(')');
}
return sb.toString();
}
}
Loading

0 comments on commit 3f7ca42

Please sign in to comment.