Skip to content

Commit

Permalink
Fix implicit call reference in summary representation
Browse files Browse the repository at this point in the history
Bug: #47963
Change-Id: Ice412be0ced087f90486e9e1612e3be616ec6d6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225760
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and Commit Bot committed Dec 30, 2021
1 parent 0870e9f commit 4b16e02
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import 'package:meta/meta.dart';
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 193;
static const int DATA_VERSION = 194;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
18 changes: 18 additions & 0 deletions pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class AstBinaryReader {
return _readGenericFunctionType();
case Tag.IfElement:
return _readIfElement();
case Tag.ImplicitCallReference:
return _readImplicitCallReference();
case Tag.IndexExpression:
return _readIndexExpression();
case Tag.IntegerLiteralNegative1:
Expand Down Expand Up @@ -647,6 +649,22 @@ class AstBinaryReader {
);
}

ImplicitCallReference _readImplicitCallReference() {
var expression = readNode() as Expression;
var typeArguments = _readOptionalNode() as TypeArgumentList?;
var typeArgumentTypes = _reader.readOptionalTypeList()!;
var staticElement = _reader.readElement() as MethodElement;

var node = astFactory.implicitCallReference(
expression: expression,
staticElement: staticElement,
typeArguments: typeArguments,
typeArgumentTypes: typeArgumentTypes,
);
_readExpressionResolution(node);
return node;
}

IndexExpression _readIndexExpression() {
var flags = _readByte();
var target = _readOptionalNode() as Expression?;
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/summary2/ast_binary_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Tag {
static const int GenericFunctionType = 21;
static const int HideCombinator = 48;
static const int IfElement = 63;
static const int ImplicitCallReference = 104;
static const int IndexExpression = 98;
static const int InstanceCreationExpression = 25;
static const int IntegerLiteralNegative = 73;
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
_writeOptionalNode(node.elseElement);
}

@override
void visitImplicitCallReference(ImplicitCallReference node) {
_writeByte(Tag.ImplicitCallReference);
_writeNode(node.expression);
_writeOptionalNode(node.typeArguments);
_sink.writeOptionalTypeList(node.typeArgumentTypes);

_sink.writeElement(node.staticElement);

_storeExpression(node);
}

@override
void visitIndexExpression(IndexExpression node) {
_writeByte(Tag.IndexExpression);
Expand Down
13 changes: 13 additions & 0 deletions pkg/analyzer/test/src/summary/resolved_ast_printer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,19 @@ class ResolvedAstPrinter extends ThrowingAstVisitor<void> {
});
}

@override
void visitImplicitCallReference(ImplicitCallReference node) {
_writeln('ImplicitCallReference');
_withIndent(() {
var properties = _Properties();
properties.addNode('expression', node.expression);
properties.addNode('typeArguments', node.typeArguments);
properties.addTypeList('typeArgumentTypes', node.typeArgumentTypes);
_addExpression(properties, node);
_writeProperties(properties);
});
}

@override
void visitImportDirective(ImportDirective node) {
_writeNextCodeLine(node);
Expand Down
57 changes: 57 additions & 0 deletions pkg/analyzer/test/src/summary/resynthesize_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19495,6 +19495,63 @@ library
''');
}

test_implicitCallTearoff() async {
var library = await checkLibrary(r'''
class C {
void call() {}
}

class D {
const D(C c) : this.named(c);

const D.named(void Function() f);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
synthetic @-1
methods
call @17
returnType: void
class D @36
constructors
const @48
parameters
requiredPositional c @52
type: C
constantInitializers
RedirectingConstructorInvocation
argumentList: ArgumentList
arguments
ImplicitCallReference
expression: SimpleIdentifier
staticElement: c@52
staticType: C
token: c @68
staticType: void Function()
leftParenthesis: ( @67
rightParenthesis: ) @69
constructorName: SimpleIdentifier
staticElement: self::@class::D::@constructor::named
staticType: null
token: named @62
period: . @61
staticElement: self::@class::D::@constructor::named
thisKeyword: this @57
redirectedConstructor: self::@class::D::@constructor::named
const named @83
periodOffset: 82
nameEnd: 88
parameters
requiredPositional f @105
type: void Function()
''');
}

test_implicitConstructor_named_const() async {
var library = await checkLibrary('''
class C {
Expand Down

0 comments on commit 4b16e02

Please sign in to comment.