Issue 51561. Fix for a mixin field inference.

Bug: https://github.com/dart-lang/sdk/issues/51561
Change-Id: Ie8654a4e3bb73dd41c7f6fa291fe531a5dcc9fa4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287641
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-03-08 22:45:15 +00:00 committed by Commit Queue
parent b04cb92b73
commit b1b1f47b95
2 changed files with 125 additions and 1 deletions

View file

@ -244,7 +244,7 @@ class _PropertyInducingElementTypeInference
final enclosingElement = _element.enclosingElement;
final enclosingClassElement =
enclosingElement is ClassElement ? enclosingElement : null;
enclosingElement is InterfaceElement ? enclosingElement : null;
var astResolver = AstResolver(_linker, _unitElement, _scope,
enclosingClassElement: enclosingClassElement);

View file

@ -665,6 +665,130 @@ MethodInvocation
''');
}
test_hasReceiver_super_class_field() async {
await assertNoErrorsInCode(r'''
class A {
int foo() => 0;
}
class B extends A {
late final v = super.foo();
}
''');
var node = findNode.methodInvocation('super.foo()');
assertResolvedNodeText(node, r'''
MethodInvocation
target: SuperExpression
superKeyword: super
staticType: B
operator: .
methodName: SimpleIdentifier
token: foo
staticElement: self::@class::A::@method::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: int Function()
staticType: int
''');
}
test_hasReceiver_super_class_method() async {
await assertNoErrorsInCode(r'''
class A {
void foo() {}
}
class B extends A {
void bar() {
super.foo();
}
}
''');
var node = findNode.methodInvocation('super.foo()');
assertResolvedNodeText(node, r'''
MethodInvocation
target: SuperExpression
superKeyword: super
staticType: B
operator: .
methodName: SimpleIdentifier
token: foo
staticElement: self::@class::A::@method::foo
staticType: void Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: void Function()
staticType: void
''');
}
test_hasReceiver_super_mixin_field() async {
await assertNoErrorsInCode(r'''
class A {
int foo() => 0;
}
mixin M on A {
late final v = super.foo();
}
''');
var node = findNode.methodInvocation('super.foo()');
assertResolvedNodeText(node, r'''
MethodInvocation
target: SuperExpression
superKeyword: super
staticType: M
operator: .
methodName: SimpleIdentifier
token: foo
staticElement: self::@class::A::@method::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: int Function()
staticType: int
''');
}
test_hasReceiver_super_mixin_method() async {
await assertNoErrorsInCode(r'''
class A {
void foo() {}
}
mixin M on A {
void bar() {
super.foo();
}
}
''');
var node = findNode.methodInvocation('super.foo()');
assertResolvedNodeText(node, r'''
MethodInvocation
target: SuperExpression
superKeyword: super
staticType: M
operator: .
methodName: SimpleIdentifier
token: foo
staticElement: self::@class::A::@method::foo
staticType: void Function()
argumentList: ArgumentList
leftParenthesis: (
rightParenthesis: )
staticInvokeType: void Function()
staticType: void
''');
}
test_hasReceiver_typeAlias_staticMethod() async {
await assertNoErrorsInCode(r'''
class A {