Issue 50496. Add mixin super invoked names to the unlinked signature.

Bug: https://github.com/dart-lang/sdk/issues/50496
Change-Id: I09c6dbc025cecc52e8f0340388bbf2b79ea78057
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273831
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-12-07 22:17:22 +00:00 committed by Commit Queue
parent 0fd211facd
commit 52be8e0f3e
4 changed files with 157 additions and 45 deletions

View file

@ -105,20 +105,20 @@ class AnalysisServerTest with ResourceProviderMixin {
InstrumentationService.NULL_SERVICE);
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/50496')
Future<void> test_cache() async {
/// See https://github.com/dart-lang/sdk/issues/50496
Future<void> test_caching_mixin_superInvokedNames_setter_change() async {
var lib = convertPath('/lib');
newFolder(lib);
var foo = newFile('/lib/foo.dart', '''
abstract class A {
set foo(_);
class A {
set foo(int _) {}
}
mixin M on A {
void bar() {
super.foo = 0;
super.boo = 0;
}
}
abstract class X extends A with M {}
class X extends A with M {}
''');
await server.setAnalysisRoots('0', [lib], []);
await server.onAnalysisComplete;
@ -127,32 +127,15 @@ abstract class X extends A with M {}
server.updateContent('0', {
foo.path: AddContentOverlay('''
abstract class A {
set boo(_);
class A {
set foo(int _) {}
}
mixin M on A {
void bar() {
super.foo = 0;
}
}
abstract class X extends A with M {}
''')
});
await server.onAnalysisComplete;
expect(server.statusAnalyzing, isFalse);
channel.notificationsReceived.clear();
server.updateContent('0', {
foo.path: AddContentOverlay('''
abstract class A {
set boo(_);
}
mixin M on A {
void bar() {
super.boo = 0;
}
}
abstract class X extends A with M {}
class X extends A with M {}
''')
});
await server.onAnalysisComplete;
@ -161,13 +144,9 @@ abstract class X extends A with M {}
expect(notifications, hasLength(1));
var notification = notifications.first;
expect(notification.event, 'analysis.errors');
var params = notification.params;
expect(params, isNotNull);
var errors = params!['errors'] as List<Map<String, dynamic>>;
expect(errors, hasLength(1));
var error = errors.first;
var message = error['message'];
expect(message, contains("boo"));
var params = notification.params!;
var errors = params['errors'] as List<Map<String, Object?>>;
expect(errors, isEmpty);
}
/// Test that modifying package_config again while a context rebuild is in

View file

@ -7,6 +7,7 @@ import 'dart:typed_data';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/src/dart/ast/invokes_super_self.dart';
import 'package:analyzer/src/dart/ast/mixin_super_invoked_names.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/summary/api_signature.dart';
import 'package:collection/collection.dart';
@ -150,6 +151,7 @@ class _UnitApiSignatureComputer {
void _addMixin(MixinDeclaration node) {
_addTokens(node.beginToken, node.leftBracket);
_addClassMembers(node.members, false);
signature.addStringList(node.superInvokedNames);
}
void _addNode(AstNode? node) {
@ -227,3 +229,12 @@ class _UnitApiSignatureComputer {
}
}
}
extension on MixinDeclaration {
List<String> get superInvokedNames {
var names = <String>{};
var collector = MixinSuperInvokedNamesCollector(names);
accept(collector);
return names.toList(growable: false);
}
}

View file

@ -101,6 +101,14 @@ class ApiSignature {
addBytes(bytes);
}
/// Collect a string list, with the length.
void addStringList(List<String> values) {
addInt(values.length);
for (var value in values) {
addString(value);
}
}
/// Collect the given [Uint32List].
void addUint32List(Uint32List data) {
addBytes(data.buffer.asUint8List());

View file

@ -364,6 +364,22 @@ class B implements A {}
''');
}
test_class_method_body_block_invokesSuperSelf_false_differentName() {
_assertSameSignature('''
class A {
void foo() {
super.bar();
}
}
''', '''
class A {
void foo() {
super.bar2();
}
}
''');
}
test_class_modifier() {
_assertNotSameSignature(r'''
class C {}
@ -457,18 +473,6 @@ static const int a = 2;
''');
}
test_classLike_method_body_block_invokesSuperSelf_false_differentName() {
_assertSameSignature_classLike(r'''
void foo() {
super.bar();
}
''', r'''
void foo() {
super.bar2();
}
''');
}
test_classLike_method_body_block_invokesSuperSelf_falseToTrue() {
_assertNotSameSignature_classLike(r'''
void foo() {}
@ -1314,6 +1318,116 @@ mixin M on A {}
''');
}
test_mixin_superInvokedNames_indexRead_add() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super[0] = 0;
}
}
''', r'''
mixin M {
void foo() {
super[0];
super[0] = 0;
}
}
''');
}
test_mixin_superInvokedNames_indexWrite_add() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super[0];
}
}
''', r'''
mixin M {
void foo() {
super[0];
super[0] = 0;
}
}
''');
}
test_mixin_superInvokedNames_methodInvocation_add() {
_assertNotSameSignature(r'''
mixin M {
void foo() {}
}
''', r'''
mixin M {
void foo() {
super.bar();
}
}
''');
}
test_mixin_superInvokedNames_methodInvocation_change() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super.bar();
}
}
''', r'''
mixin M {
void foo() {
super.bar2();
}
}
''');
}
test_mixin_superInvokedNames_methodInvocation_remove() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super.bar();
}
}
''', r'''
mixin M {
void foo() {}
}
''');
}
test_mixin_superInvokedNames_propertyRead_change() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super.bar;
}
}
''', r'''
mixin M {
void foo() {
super.bar2;
}
}
''');
}
test_mixin_superInvokedNames_propertyWrite_change() {
_assertNotSameSignature(r'''
mixin M {
void foo() {
super.bar = 0;
}
}
''', r'''
mixin M {
void foo() {
super.bar2 = 2;
}
}
''');
}
test_topLevelVariable_final_add() {
_assertNotSameSignature(r'''
int a = 0;