mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:48:25 +00:00
Issue 33553. For get/set. Don't report ABSTRACT_SUPER_MEMBER_REFERENCE if the nominal superclass has noSuchMethod().
R=brianwilkerson@google.com, paulberry@google.com Bug: https://github.com/dart-lang/sdk/issues/33553 Change-Id: Ic0e142519a839607560ae0d0e551424a9b32c954 Reviewed-on: https://dart-review.googlesource.com/c/84045 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
51f34ea580
commit
9cf51348d4
|
@ -491,8 +491,9 @@ class MethodInvocationResolver {
|
|||
var calleeType = _getCalleeType(targetType);
|
||||
_setResolution(node, calleeType);
|
||||
|
||||
ClassElementImpl receiverSuperClass =
|
||||
receiverType.element.supertype.element;
|
||||
ClassElementImpl receiverSuperClass = AbstractClassElementImpl.getImpl(
|
||||
receiverType.element.supertype.element,
|
||||
);
|
||||
if (receiverSuperClass.hasNoSuchMethod) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1654,10 +1654,16 @@ class ElementResolver extends SimpleAstVisitor<Object> {
|
|||
propertyName.name, _definingLibrary,
|
||||
setter: propertyName.inSetterContext(), concrete: false);
|
||||
if (staticElement != null) {
|
||||
_resolver.errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
|
||||
propertyName,
|
||||
[staticElement.kind.displayName, propertyName.name]);
|
||||
ClassElementImpl receiverSuperClass =
|
||||
AbstractClassElementImpl.getImpl(
|
||||
staticType.element.supertype.element,
|
||||
);
|
||||
if (!receiverSuperClass.hasNoSuchMethod) {
|
||||
_resolver.errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
|
||||
propertyName,
|
||||
[staticElement.kind.displayName, propertyName.name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
105
pkg/analyzer/test/src/dart/resolution/property_access_test.dart
Normal file
105
pkg/analyzer/test/src/dart/resolution/property_access_test.dart
Normal file
|
@ -0,0 +1,105 @@
|
|||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'driver_resolution.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(PropertyAccessResolutionTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class PropertyAccessResolutionTest extends DriverResolutionTest {
|
||||
test_get_error_abstractSuperMemberReference_mixinHasNoSuchMethod() async {
|
||||
addTestFile('''
|
||||
class A {
|
||||
int get foo;
|
||||
noSuchMethod(im) => 1;
|
||||
}
|
||||
|
||||
class B extends Object with A {
|
||||
get foo => super.foo; // ref
|
||||
noSuchMethod(im) => 2;
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
assertTestErrors([CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
|
||||
|
||||
var access = findNode.propertyAccess('foo; // ref');
|
||||
assertPropertyAccess(access, findElement.getter('foo', of: 'A'), 'int');
|
||||
assertSuperExpression(access.target);
|
||||
}
|
||||
|
||||
test_get_error_abstractSuperMemberReference_OK_superHasNoSuchMethod() async {
|
||||
addTestFile(r'''
|
||||
class A {
|
||||
int get foo;
|
||||
noSuchMethod(im) => 1;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
get foo => super.foo; // ref
|
||||
noSuchMethod(im) => 2;
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
assertNoTestErrors();
|
||||
|
||||
var access = findNode.propertyAccess('super.foo; // ref');
|
||||
assertPropertyAccess(access, findElement.getter('foo', of: 'A'), 'int');
|
||||
assertSuperExpression(access.target);
|
||||
}
|
||||
|
||||
test_set_error_abstractSuperMemberReference_mixinHasNoSuchMethod() async {
|
||||
addTestFile('''
|
||||
class A {
|
||||
set foo(int a);
|
||||
noSuchMethod(im) {}
|
||||
}
|
||||
|
||||
class B extends Object with A {
|
||||
set foo(v) => super.foo = v; // ref
|
||||
noSuchMethod(im) {}
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
assertTestErrors([CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
|
||||
|
||||
var access = findNode.propertyAccess('foo = v; // ref');
|
||||
assertPropertyAccess(
|
||||
access,
|
||||
findElement.setter('foo', className: 'A'),
|
||||
'int',
|
||||
);
|
||||
assertSuperExpression(access.target);
|
||||
}
|
||||
|
||||
test_set_error_abstractSuperMemberReference_OK_superHasNoSuchMethod() async {
|
||||
addTestFile(r'''
|
||||
class A {
|
||||
set foo(int a);
|
||||
noSuchMethod(im) => 1;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
set foo(v) => super.foo = v; // ref
|
||||
noSuchMethod(im) => 2;
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
assertNoTestErrors();
|
||||
|
||||
var access = findNode.propertyAccess('foo = v; // ref');
|
||||
assertPropertyAccess(
|
||||
access,
|
||||
findElement.setter('foo', className: 'A'),
|
||||
'int',
|
||||
);
|
||||
assertSuperExpression(access.target);
|
||||
}
|
||||
}
|
|
@ -275,6 +275,15 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
|||
assertType(invocation, expectedType);
|
||||
}
|
||||
|
||||
void assertPropertyAccess(
|
||||
PropertyAccess access,
|
||||
Element expectedElement,
|
||||
String expectedType,
|
||||
) {
|
||||
assertElement(access.propertyName, expectedElement);
|
||||
assertType(access, expectedType);
|
||||
}
|
||||
|
||||
void assertNamedParameterRef(String search, String name) {
|
||||
var ref = findNode.simple(search);
|
||||
assertElement(ref, findElement.parameter(name));
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'instance_member_inference_mixin_test.dart'
|
|||
import 'method_invocation_test.dart' as method_invocation_test;
|
||||
import 'mixin_test.dart' as mixin_test;
|
||||
import 'optional_const_test.dart' as optional_const_test;
|
||||
import 'property_access_test.dart' as property_access_test;
|
||||
import 'top_type_inference_test.dart' as top_type_inference_test;
|
||||
|
||||
main() {
|
||||
|
@ -38,6 +39,7 @@ main() {
|
|||
method_invocation_test.main();
|
||||
mixin_test.main();
|
||||
optional_const_test.main();
|
||||
property_access_test.main();
|
||||
top_type_inference_test.main();
|
||||
}, name: 'resolution');
|
||||
}
|
||||
|
|
|
@ -98,8 +98,6 @@ setter3_test/01: CompileTimeError # Invalid test, see https://github.com/dart-la
|
|||
setter3_test/02: CompileTimeError # Invalid test, see https://github.com/dart-lang/sdk/issues/33837
|
||||
super_bound_closure_test/none: CompileTimeError
|
||||
super_call4_test/01: MissingCompileTimeError
|
||||
super_no_such_method2_test: CompileTimeError # Invalid test, probably, see https://github.com/dart-lang/sdk/issues/33963
|
||||
super_no_such_method3_test: CompileTimeError # Invalid test, probably, see https://github.com/dart-lang/sdk/issues/33963
|
||||
super_setter_test: CompileTimeError # Invalid test, see https://github.com/dart-lang/sdk/issues/33837
|
||||
syntax_test/60: MissingCompileTimeError
|
||||
syntax_test/61: MissingCompileTimeError
|
||||
|
|
|
@ -127,8 +127,6 @@ setter3_test/02: CompileTimeError # Invalid test, see https://github.com/dart-la
|
|||
stacktrace_test: RuntimeError # Issue 29920
|
||||
super_bound_closure_test/none: CompileTimeError
|
||||
super_call4_test/01: MissingCompileTimeError
|
||||
super_no_such_method2_test: CompileTimeError # Invalid test, probably, see https://github.com/dart-lang/sdk/issues/33963
|
||||
super_no_such_method3_test: CompileTimeError # Invalid test, probably, see https://github.com/dart-lang/sdk/issues/33963
|
||||
super_operator_index5_test: RuntimeError # 33470
|
||||
super_operator_index7_test: RuntimeError # 33470
|
||||
super_operator_index8_test: RuntimeError # 33470
|
||||
|
|
Loading…
Reference in a new issue