| Index: pkg/kernel/lib/transformations/closure/converter.dart
|
| diff --git a/pkg/kernel/lib/transformations/closure/converter.dart b/pkg/kernel/lib/transformations/closure/converter.dart
|
| index e1865f7fd6d90a6c04a8e0dbeba37456490f612f..658dea8914dd8fd629eea358905acaf51ee5c676 100644
|
| --- a/pkg/kernel/lib/transformations/closure/converter.dart
|
| +++ b/pkg/kernel/lib/transformations/closure/converter.dart
|
| @@ -230,6 +230,7 @@ class ClosureConverter extends Transformer {
|
| }
|
| }
|
| rewriter = null;
|
| + context = null;
|
| // Transform constructor body.
|
| FunctionNode function = node.function;
|
| if (function.body != null && function.body is! EmptyStatement) {
|
| @@ -424,6 +425,8 @@ class ClosureConverter extends Transformer {
|
|
|
| FunctionNode function = node.function;
|
| if (function.body != null) {
|
| + bool hadSingleStatementBody = function.body is! Block;
|
| +
|
| setupContextForFunctionBody(function);
|
| VariableDeclaration self = thisAccess[currentMemberFunction];
|
| if (self != null) {
|
| @@ -431,6 +434,22 @@ class ClosureConverter extends Transformer {
|
| }
|
| node.transformChildren(this);
|
| resetContext();
|
| +
|
| + // Here a special case is handled: the body of the procedure was a single
|
| + // statement and after the transformation it is a block with a single
|
| + // statement inside. In this case we make this statement the body of the
|
| + // procedure again. It is required to follow the conventions imposed by
|
| + // [addClass] in [DillLibraryBuilder].
|
| + // See [dill_library_builder.dart]
|
| + // (../../../../front_end/lib/src/fasta/dill/dill_library_builder.dart)
|
| + // for details.
|
| + if (hadSingleStatementBody && function.body is Block) {
|
| + Block body = function.body;
|
| + if (body.statements.length == 1) {
|
| + function.body = body.statements[0];
|
| + function.body.parent = function;
|
| + }
|
| + }
|
| }
|
|
|
| return node;
|
| @@ -483,7 +502,7 @@ class ClosureConverter extends Transformer {
|
| TreeNode visitBlock(Block node) {
|
| return saveContext(() {
|
| BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node);
|
| - blockRewriter.transformStatements(node, this);
|
| + blockRewriter.transformStatements(this);
|
| return node;
|
| });
|
| }
|
| @@ -643,9 +662,8 @@ class ClosureConverter extends Transformer {
|
| TreeNode visitPropertyGet(PropertyGet node) {
|
| Name tearOffName = tearOffGetterNames[node.name];
|
| if (tearOffName != null) {
|
| - MethodInvocation replacement = new MethodInvocation(
|
| - node.receiver, tearOffName, new Arguments(<Expression>[]));
|
| - return super.visitMethodInvocation(replacement);
|
| + PropertyGet replacement = new PropertyGet(node.receiver, tearOffName);
|
| + return super.visitPropertyGet(replacement);
|
| }
|
| return super.visitPropertyGet(node);
|
| }
|
| @@ -871,7 +889,7 @@ class ClosureConverter extends Transformer {
|
| self, procedure, contextVariable, parent.expression)));
|
|
|
| Procedure tearOffMethod = new Procedure(
|
| - name, ProcedureKind.Method, tearOffMethodFunction,
|
| + name, ProcedureKind.Getter, tearOffMethodFunction,
|
| fileUri: currentFileUri);
|
| newClassMembers.add(tearOffMethod);
|
|
|
|
|