Skip to content

Commit b7efcd2

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Report NO_COMBINED_SUPER_SIGNATURE.
dart-lang/language#975 Change-Id: I8ecd191efa84f17d36ea09ef1db33a401c67fda3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151093 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent a1fc2ea commit b7efcd2

23 files changed

+395
-239
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ const List<ErrorCode> errorCodeValues = [
242242
CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS,
243243
CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS,
244244
CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS,
245+
CompileTimeErrorCode.NO_COMBINED_SUPER_SIGNATURE,
245246
CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT,
246247
CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT,
247248
CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT,

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ typedef WorkToWaitAfterComputingResult = Future<void> Function(String path);
9191
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
9292
class AnalysisDriver implements AnalysisDriverGeneric {
9393
/// The version of data format, should be incremented on every format change.
94-
static const int DATA_VERSION = 101;
94+
static const int DATA_VERSION = 102;
9595

9696
/// The length of the list returned by [_computeDeclaredVariablesSignature].
9797
static const int _declaredVariablesSignatureLength = 4;

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,6 +5878,18 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
58785878
return super.name;
58795879
}
58805880

5881+
/// Return the error reported during type inference for this method, or
5882+
/// `null` if this method is not a subject of type inference, or there was
5883+
/// no error.
5884+
TopLevelInferenceError get typeInferenceError {
5885+
if (linkedNode != null) {
5886+
return linkedContext.getTypeInferenceError(linkedNode);
5887+
}
5888+
5889+
// We don't support type inference errors without linking.
5890+
return null;
5891+
}
5892+
58815893
@override
58825894
T accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this);
58835895
}
@@ -6421,7 +6433,9 @@ abstract class NonParameterVariableElementImpl extends VariableElementImpl {
64216433
_type = type;
64226434
}
64236435

6424-
@override
6436+
/// Return the error reported during type inference for this variable, or
6437+
/// `null` if this variable is not a subject of type inference, or there was
6438+
/// no error.
64256439
TopLevelInferenceError get typeInferenceError {
64266440
if (linkedNode != null) {
64276441
return linkedContext.getTypeInferenceError(linkedNode);
@@ -6703,16 +6717,6 @@ class ParameterElementImpl extends VariableElementImpl
67036717
@override
67046718
DartType get type => ElementTypeProvider.current.getVariableType(this);
67056719

6706-
@override
6707-
TopLevelInferenceError get typeInferenceError {
6708-
if (linkedNode != null) {
6709-
return linkedContext.getTypeInferenceError(linkedNode);
6710-
}
6711-
6712-
// We don't support type inference errors without linking.
6713-
return null;
6714-
}
6715-
67166720
@override
67176721
DartType get typeInternal {
67186722
if (linkedNode != null) {
@@ -7846,13 +7850,6 @@ abstract class VariableElementImpl extends ElementImpl
78467850
_type = type;
78477851
}
78487852

7849-
/// Return the error reported during type inference for this variable, or
7850-
/// `null` if this variable is not a subject of type inference, or there was
7851-
/// no error.
7852-
TopLevelInferenceError get typeInferenceError {
7853-
return null;
7854-
}
7855-
78567853
/// Gets the element's type, without going through the indirection of
78577854
/// [ElementTypeProvider].
78587855
///

pkg/analyzer/lib/src/error/codes.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,26 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
42474247
correction: "Try adding an empty argument list.",
42484248
hasPublishedDocs: true);
42494249

4250+
/**
4251+
* A method `m` of a class `C` is subject to override inference if it is
4252+
* missing one or more component types of its signature, and one or more of
4253+
* the direct superinterfaces of `C` has a member named `m` (*that is, `C.m`
4254+
* overrides one or more declarations*). Each missing type is filled in with
4255+
* the corresponding type from the combined member signature `s` of `m` in
4256+
* the direct superinterfaces of `C`.
4257+
*
4258+
* A compile-time error occurs if `s` does not exist.
4259+
*
4260+
* Parameters:
4261+
* 0: the name of the class where override error was detected
4262+
* 1: the list of candidate signatures which cannot be combined
4263+
*/
4264+
static const CompileTimeErrorCode NO_COMBINED_SUPER_SIGNATURE =
4265+
CompileTimeErrorCode('NO_COMBINED_SUPER_SIGNATURE',
4266+
"No valid combined signature in superinterfaces of '{0}': {1}.",
4267+
correction: "Try providing explicit types for this method's "
4268+
"parameters and return type.");
4269+
42504270
/**
42514271
* Parameters:
42524272
* 0: the name of the superclass that does not define an implicitly invoked

pkg/analyzer/lib/src/error/inheritance_override.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:analyzer/src/error/correct_override.dart';
1818
import 'package:analyzer/src/error/getter_setter_types_verifier.dart';
1919
import 'package:analyzer/src/generated/resolver.dart' show TypeSystemImpl;
2020
import 'package:analyzer/src/generated/type_system.dart';
21+
import 'package:analyzer/src/summary/idl.dart';
2122
import 'package:meta/meta.dart';
2223

2324
class InheritanceOverrideVerifier {
@@ -174,6 +175,11 @@ class _ClassVerifier {
174175
_checkDeclaredMember(field.name, libraryUri, fieldElement.setter);
175176
}
176177
} else if (member is MethodDeclaration) {
178+
var hasError = _reportNoCombinedSuperSignature(member);
179+
if (hasError) {
180+
continue;
181+
}
182+
177183
_checkDeclaredMember(member.name, libraryUri, member.declaredElement,
178184
methodParameterNodes: member.parameters?.parameters);
179185
}
@@ -700,6 +706,26 @@ class _ClassVerifier {
700706
}
701707
}
702708

709+
bool _reportNoCombinedSuperSignature(MethodDeclaration node) {
710+
var element = node.declaredElement;
711+
if (element is MethodElementImpl) {
712+
var inferenceError = element.typeInferenceError;
713+
if (inferenceError?.kind ==
714+
TopLevelInferenceErrorKind.overrideNoCombinedSuperSignature) {
715+
reporter.reportErrorForNode(
716+
CompileTimeErrorCode.NO_COMBINED_SUPER_SIGNATURE,
717+
node.name,
718+
[
719+
classElement.name,
720+
inferenceError.arguments[0],
721+
],
722+
);
723+
return true;
724+
}
725+
}
726+
return false;
727+
}
728+
703729
static bool _constantValuesEqual(DartObject x, DartObject y) {
704730
// If either constant value couldn't be computed due to an error, the
705731
// corresponding DartObject will be `null`. Since an error has already been

pkg/analyzer/lib/src/summary/format.dart

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,13 +7272,15 @@ class LinkedNodeBuilder extends Object
72727272

72737273
@override
72747274
TopLevelInferenceErrorBuilder get topLevelTypeInferenceError {
7275-
assert(kind == idl.LinkedNodeKind.simpleFormalParameter ||
7275+
assert(kind == idl.LinkedNodeKind.methodDeclaration ||
7276+
kind == idl.LinkedNodeKind.simpleFormalParameter ||
72767277
kind == idl.LinkedNodeKind.variableDeclaration);
72777278
return _variantField_32;
72787279
}
72797280

72807281
set topLevelTypeInferenceError(TopLevelInferenceErrorBuilder value) {
7281-
assert(kind == idl.LinkedNodeKind.simpleFormalParameter ||
7282+
assert(kind == idl.LinkedNodeKind.methodDeclaration ||
7283+
kind == idl.LinkedNodeKind.simpleFormalParameter ||
72827284
kind == idl.LinkedNodeKind.variableDeclaration);
72837285
_variantField_32 = value;
72847286
}
@@ -8063,6 +8065,7 @@ class LinkedNodeBuilder extends Object
80638065
LinkedNodeBuilder methodDeclaration_typeParameters,
80648066
int informativeId,
80658067
bool methodDeclaration_hasOperatorEqualWithParameterTypeFromObject,
8068+
TopLevelInferenceErrorBuilder topLevelTypeInferenceError,
80668069
}) : _kind = idl.LinkedNodeKind.methodDeclaration,
80678070
_variantField_24 = actualReturnType,
80688071
_variantField_4 = annotatedNode_metadata,
@@ -8072,7 +8075,8 @@ class LinkedNodeBuilder extends Object
80728075
_variantField_9 = methodDeclaration_typeParameters,
80738076
_variantField_36 = informativeId,
80748077
_variantField_31 =
8075-
methodDeclaration_hasOperatorEqualWithParameterTypeFromObject;
8078+
methodDeclaration_hasOperatorEqualWithParameterTypeFromObject,
8079+
_variantField_32 = topLevelTypeInferenceError;
80768080

80778081
LinkedNodeBuilder.methodInvocation({
80788082
LinkedNodeTypeBuilder invocationExpression_invokeType,
@@ -8739,6 +8743,7 @@ class LinkedNodeBuilder extends Object
87398743
methodDeclaration_returnType?.flushInformative();
87408744
methodDeclaration_typeParameters?.flushInformative();
87418745
informativeId = null;
8746+
topLevelTypeInferenceError?.flushInformative();
87428747
} else if (kind == idl.LinkedNodeKind.methodInvocation) {
87438748
invocationExpression_invokeType?.flushInformative();
87448749
methodInvocation_methodName?.flushInformative();
@@ -9939,6 +9944,8 @@ class LinkedNodeBuilder extends Object
99399944
signature.addBool(
99409945
this.methodDeclaration_hasOperatorEqualWithParameterTypeFromObject ==
99419946
true);
9947+
signature.addBool(this.topLevelTypeInferenceError != null);
9948+
this.topLevelTypeInferenceError?.collectApiSignature(signature);
99429949
signature.addString(this.name ?? '');
99439950
} else if (kind == idl.LinkedNodeKind.methodInvocation) {
99449951
signature.addInt(this.kind == null ? 0 : this.kind.index);
@@ -12948,7 +12955,8 @@ class _LinkedNodeImpl extends Object
1294812955

1294912956
@override
1295012957
idl.TopLevelInferenceError get topLevelTypeInferenceError {
12951-
assert(kind == idl.LinkedNodeKind.simpleFormalParameter ||
12958+
assert(kind == idl.LinkedNodeKind.methodDeclaration ||
12959+
kind == idl.LinkedNodeKind.simpleFormalParameter ||
1295212960
kind == idl.LinkedNodeKind.variableDeclaration);
1295312961
_variantField_32 ??= const _TopLevelInferenceErrorReader()
1295412962
.vTableGet(_bc, _bcOffset, 32, null);
@@ -14085,6 +14093,10 @@ abstract class _LinkedNodeMixin implements idl.LinkedNode {
1408514093
_result["methodDeclaration_hasOperatorEqualWithParameterTypeFromObject"] =
1408614094
methodDeclaration_hasOperatorEqualWithParameterTypeFromObject;
1408714095
}
14096+
if (topLevelTypeInferenceError != null) {
14097+
_result["topLevelTypeInferenceError"] =
14098+
topLevelTypeInferenceError.toJson();
14099+
}
1408814100
}
1408914101
if (kind == idl.LinkedNodeKind.methodInvocation) {
1409014102
if (invocationExpression_invokeType != null) {
@@ -15441,6 +15453,7 @@ abstract class _LinkedNodeMixin implements idl.LinkedNode {
1544115453
"methodDeclaration_hasOperatorEqualWithParameterTypeFromObject":
1544215454
methodDeclaration_hasOperatorEqualWithParameterTypeFromObject,
1544315455
"name": name,
15456+
"topLevelTypeInferenceError": topLevelTypeInferenceError,
1544415457
};
1544515458
}
1544615459
if (kind == idl.LinkedNodeKind.methodInvocation) {
@@ -17655,7 +17668,6 @@ class TopLevelInferenceErrorBuilder extends Object
1765517668
implements idl.TopLevelInferenceError {
1765617669
List<String> _arguments;
1765717670
idl.TopLevelInferenceErrorKind _kind;
17658-
int _slot;
1765917671

1766017672
@override
1766117673
List<String> get arguments => _arguments ??= <String>[];
@@ -17674,29 +17686,16 @@ class TopLevelInferenceErrorBuilder extends Object
1767417686
this._kind = value;
1767517687
}
1767617688

17677-
@override
17678-
int get slot => _slot ??= 0;
17679-
17680-
/// The slot id (which is unique within the compilation unit) identifying the
17681-
/// target of type inference with which this [TopLevelInferenceError] is
17682-
/// associated.
17683-
set slot(int value) {
17684-
assert(value == null || value >= 0);
17685-
this._slot = value;
17686-
}
17687-
1768817689
TopLevelInferenceErrorBuilder(
17689-
{List<String> arguments, idl.TopLevelInferenceErrorKind kind, int slot})
17690+
{List<String> arguments, idl.TopLevelInferenceErrorKind kind})
1769017691
: _arguments = arguments,
17691-
_kind = kind,
17692-
_slot = slot;
17692+
_kind = kind;
1769317693

1769417694
/// Flush [informative] data recursively.
1769517695
void flushInformative() {}
1769617696

1769717697
/// Accumulate non-[informative] data into [signature].
1769817698
void collectApiSignature(api_sig.ApiSignature signature) {
17699-
signature.addInt(this._slot ?? 0);
1770017699
signature.addInt(this._kind == null ? 0 : this._kind.index);
1770117700
if (this._arguments == null) {
1770217701
signature.addInt(0);
@@ -17716,13 +17715,10 @@ class TopLevelInferenceErrorBuilder extends Object
1771617715
}
1771717716
fbBuilder.startTable();
1771817717
if (offset_arguments != null) {
17719-
fbBuilder.addOffset(2, offset_arguments);
17718+
fbBuilder.addOffset(1, offset_arguments);
1772017719
}
1772117720
if (_kind != null && _kind != idl.TopLevelInferenceErrorKind.assignment) {
17722-
fbBuilder.addUint8(1, _kind.index);
17723-
}
17724-
if (_slot != null && _slot != 0) {
17725-
fbBuilder.addUint32(0, _slot);
17721+
fbBuilder.addUint8(0, _kind.index);
1772617722
}
1772717723
return fbBuilder.endTable();
1772817724
}
@@ -17747,27 +17743,20 @@ class _TopLevelInferenceErrorImpl extends Object
1774717743

1774817744
List<String> _arguments;
1774917745
idl.TopLevelInferenceErrorKind _kind;
17750-
int _slot;
1775117746

1775217747
@override
1775317748
List<String> get arguments {
1775417749
_arguments ??= const fb.ListReader<String>(fb.StringReader())
17755-
.vTableGet(_bc, _bcOffset, 2, const <String>[]);
17750+
.vTableGet(_bc, _bcOffset, 1, const <String>[]);
1775617751
return _arguments;
1775717752
}
1775817753

1775917754
@override
1776017755
idl.TopLevelInferenceErrorKind get kind {
1776117756
_kind ??= const _TopLevelInferenceErrorKindReader().vTableGet(
17762-
_bc, _bcOffset, 1, idl.TopLevelInferenceErrorKind.assignment);
17757+
_bc, _bcOffset, 0, idl.TopLevelInferenceErrorKind.assignment);
1776317758
return _kind;
1776417759
}
17765-
17766-
@override
17767-
int get slot {
17768-
_slot ??= const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 0, 0);
17769-
return _slot;
17770-
}
1777117760
}
1777217761

1777317762
abstract class _TopLevelInferenceErrorMixin
@@ -17781,17 +17770,13 @@ abstract class _TopLevelInferenceErrorMixin
1778117770
if (kind != idl.TopLevelInferenceErrorKind.assignment) {
1778217771
_result["kind"] = kind.toString().split('.')[1];
1778317772
}
17784-
if (slot != 0) {
17785-
_result["slot"] = slot;
17786-
}
1778717773
return _result;
1778817774
}
1778917775

1779017776
@override
1779117777
Map<String, Object> toMap() => {
1779217778
"arguments": arguments,
1779317779
"kind": kind,
17794-
"slot": slot,
1779517780
};
1779617781

1779717782
@override

pkg/analyzer/lib/src/summary/format.fbs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ enum TopLevelInferenceErrorKind : byte {
437437

438438
overrideConflictFieldType,
439439

440-
overrideConflictReturnType,
441-
442-
overrideConflictParameterType
440+
overrideNoCombinedSuperSignature
443441
}
444442

445443
/// Enum of token types, corresponding to AST token types.
@@ -1267,15 +1265,10 @@ table PackageBundleSdk {
12671265
/// Summary information about a top-level type inference error.
12681266
table TopLevelInferenceError {
12691267
/// The [kind] specific arguments.
1270-
arguments:[string] (id: 2);
1268+
arguments:[string] (id: 1);
12711269

12721270
/// The kind of the error.
1273-
kind:TopLevelInferenceErrorKind (id: 1);
1274-
1275-
/// The slot id (which is unique within the compilation unit) identifying the
1276-
/// target of type inference with which this [TopLevelInferenceError] is
1277-
/// associated.
1278-
slot:uint (id: 0);
1271+
kind:TopLevelInferenceErrorKind (id: 0);
12791272
}
12801273

12811274
table UnlinkedInformativeData {

0 commit comments

Comments
 (0)