[cfe] Handle access to 'this' and parameters in view instance methods

Change-Id: I033ba603cb9f289e3ab4b39977b68e0c4641c61b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273182
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2022-12-02 08:40:26 +00:00 committed by Commit Queue
parent 14d553ad9d
commit 8bda08227d
9 changed files with 182 additions and 19 deletions

View file

@ -4,19 +4,18 @@
library fasta.procedure_builder;
import 'package:front_end/src/fasta/builder/omitted_type_builder.dart';
import 'package:kernel/ast.dart';
import 'package:kernel/class_hierarchy.dart';
import '../builder/builder.dart';
import '../builder/class_builder.dart';
import '../builder/declaration_builder.dart';
import '../builder/extension_builder.dart';
import '../builder/formal_parameter_builder.dart';
import '../builder/function_builder.dart';
import '../builder/library_builder.dart';
import '../builder/member_builder.dart';
import '../builder/metadata_builder.dart';
import '../builder/omitted_type_builder.dart';
import '../builder/type_builder.dart';
import '../builder/type_variable_builder.dart';
import '../identifiers.dart';
@ -35,6 +34,7 @@ import '../source/source_loader.dart' show SourceLoader;
import '../type_inference/type_inference_engine.dart'
show IncludesTypeParametersNonCovariantly;
import '../util/helpers.dart' show DelayedActionPerformer;
import 'source_builder_mixins.dart';
import 'source_member_builder.dart';
abstract class SourceFunctionBuilder
@ -387,8 +387,9 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl
function.returnType =
returnType.build(libraryBuilder, TypeUse.returnType);
}
if (isExtensionInstanceMember) {
ExtensionBuilder extensionBuilder = parent as ExtensionBuilder;
if (isExtensionInstanceMember || isViewInstanceMember) {
SourceDeclarationBuilderMixin extensionBuilder =
parent as SourceDeclarationBuilderMixin;
_extensionThis = function.positionalParameters.first;
if (extensionBuilder.typeParameters != null) {
int count = extensionBuilder.typeParameters!.length;
@ -401,7 +402,7 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl
@override
VariableDeclaration getFormalParameter(int index) {
if (isExtensionInstanceMember) {
if (isExtensionInstanceMember || isViewInstanceMember) {
return formals![index + 1].variable!;
} else {
return formals![index].variable!;
@ -413,7 +414,9 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl
@override
VariableDeclaration? get extensionThis {
assert(_extensionThis != null || !isExtensionInstanceMember,
assert(
_extensionThis != null ||
!(isExtensionInstanceMember || isViewInstanceMember),
"ProcedureBuilder.extensionThis has not been set.");
return _extensionThis;
}
@ -422,7 +425,9 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl
List<TypeParameter>? get extensionTypeParameters {
// Use [_extensionThis] as marker for whether extension type parameters have
// been computed.
assert(_extensionThis != null || !isExtensionInstanceMember,
assert(
_extensionThis != null ||
!(isExtensionInstanceMember || isViewInstanceMember),
"ProcedureBuilder.extensionTypeParameters has not been set.");
return _extensionTypeParameters;
}

View file

@ -5,13 +5,27 @@
view class Class {
final int it;
void instanceMethod() {}
void instanceMethod() {
this;
}
void instanceMethod2(String s, [int i = 42]) {
this;
s;
i;
}
static void staticMethod() {}
}
view class GenericClass<T> {
final T it;
void instanceMethod() {}
void instanceMethod() {
this;
}
void instanceMethod2(String s, {int i = 42}) {
this;
s;
i;
}
static void staticMethod() {}
}

View file

@ -5,18 +5,44 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|instanceMethod(lowered final self::Class #this) → void {
#this;
}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [core::int i = #C1]) → void {
#this;
s;
i;
}
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i = #C1]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {
#this;
}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {core::int i = #C1}) → void {
#this;
s;
i;
}
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i = #C1}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void {}
constants {
#C1 = 42
}

View file

@ -5,18 +5,44 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|instanceMethod(lowered final self::Class #this) → void {
#this;
}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [core::int i = #C1]) → void {
#this;
s;
i;
}
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i = #C1]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {
#this;
}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {core::int i = #C1}) → void {
#this;
s;
i;
}
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i = #C1}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void {}
constants {
#C1 = 42
}

View file

@ -2,11 +2,13 @@ view
class Class {
final int it;
void instanceMethod() {}
void instanceMethod2(String s, [int i = 42]) {}
static void staticMethod() {}
}
view
class GenericClass<T> {
final T it;
void instanceMethod() {}
void instanceMethod2(String s, {int i = 42}) {}
static void staticMethod() {}
}

View file

@ -5,18 +5,44 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|instanceMethod(lowered final self::Class #this) → void {
#this;
}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [core::int i = #C1]) → void {
#this;
s;
i;
}
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i = #C1]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {
#this;
}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {core::int i = #C1}) → void {
#this;
s;
i;
}
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i = #C1}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void {}
constants {
#C1 = 42
}

View file

@ -5,18 +5,44 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|instanceMethod(lowered final self::Class #this) → void {
#this;
}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [core::int i = #C1]) → void {
#this;
s;
i;
}
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i = #C1]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {
#this;
}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {core::int i = #C1}) → void {
#this;
s;
i;
}
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i = #C1}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void {}
constants {
#C1 = 42
}

View file

@ -5,22 +5,34 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void
;
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [has-declared-initializer core::int i]) → void
;
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void
;
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void
;
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {has-declared-initializer core::int i}) → void
;
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void
;

View file

@ -5,18 +5,44 @@ import "dart:core" as core;
view Class /* representationType = core::int */ {
method instanceMethod = self::Class|instanceMethod;
tearoff instanceMethod = self::Class|get#instanceMethod;
method instanceMethod2 = self::Class|instanceMethod2;
tearoff instanceMethod2 = self::Class|get#instanceMethod2;
static method staticMethod = self::Class|staticMethod;
}
view GenericClass<T extends core::Object? = dynamic> /* representationType = T% */ {
method instanceMethod = self::GenericClass|instanceMethod;
tearoff instanceMethod = self::GenericClass|get#instanceMethod;
method instanceMethod2 = self::GenericClass|instanceMethod2;
tearoff instanceMethod2 = self::GenericClass|get#instanceMethod2;
static method staticMethod = self::GenericClass|staticMethod;
}
static method Class|instanceMethod(lowered final self::Class #this) → void {}
static method Class|instanceMethod(lowered final self::Class #this) → void {
#this;
}
static method Class|get#instanceMethod(lowered final self::Class #this) → () → void
return () → void => self::Class|instanceMethod(#this);
static method Class|instanceMethod2(lowered final self::Class #this, core::String s, [core::int i = #C1]) → void {
#this;
s;
i;
}
static method Class|get#instanceMethod2(lowered final self::Class #this) → (core::String, [core::int]) → void
return (core::String s, [core::int i = #C1]) → void => self::Class|instanceMethod2(#this, s, i);
static method Class|staticMethod() → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {}
static method GenericClass|instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod::T%> #this) → void {
#this;
}
static method GenericClass|get#instanceMethod<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod::T%> #this) → () → void
return () → void => self::GenericClass|instanceMethod<self::GenericClass|get#instanceMethod::T%>(#this);
static method GenericClass|instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|instanceMethod2::T%> #this, core::String s, {core::int i = #C1}) → void {
#this;
s;
i;
}
static method GenericClass|get#instanceMethod2<T extends core::Object? = dynamic>(lowered final self::GenericClass<self::GenericClass|get#instanceMethod2::T%> #this) → (core::String, {i: core::int}) → void
return (core::String s, {core::int i = #C1}) → void => self::GenericClass|instanceMethod2<self::GenericClass|get#instanceMethod2::T%>(#this, s, i: i);
static method GenericClass|staticMethod() → void {}
constants {
#C1 = 42
}