// Copyright (c) 2019, 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/dart/analysis/unlinked_api_signature.dart'; import 'package:analyzer/src/dart/ast/ast.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../../diagnostics/parser_diagnostics.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UnitApiSignatureTest); }); } @reflectiveTest class UnitApiSignatureTest extends ParserDiagnosticsTest { test_class_annotation() async { _assertNotSameSignature( r''' const a = 0; class C {} ''', r''' const a = 0; @a class C {} ''', ); } test_class_constructor_block_to_block_differentStatement() { _assertSameSignature( r''' class C { C() { var v = 1; } } ''', r''' class C { C() { var v = 2; } } ''', ); } test_class_constructor_block_to_block_identical() { _assertSameSignature( r''' class C { C() { var v = 1; } } ''', r''' class C { C() { var v = 1; } } ''', ); } test_class_constructor_block_to_empty() { _assertNotSameSignature( r''' class C { C() { var v = 1; } } ''', r''' class C { C(); } ''', ); } test_class_constructor_block_to_external() { _assertNotSameSignature( r''' class C { C() {} } ''', r''' class C { external C(); } ''', ); } test_class_constructor_empty_to_block() { _assertNotSameSignature( r''' class C { C(); } ''', r''' class C { C() {} } ''', ); } test_class_constructor_empty_to_empty() { _assertSameSignature( r''' class C { C(); } ''', r''' class C { C(); } ''', ); } test_class_constructor_external_to_block() { _assertNotSameSignature( r''' class C { external C(); } ''', r''' class C { C() {} } ''', ); } test_class_constructor_initializer_const() { _assertNotSameSignature( r''' class C { final int f; const C() : f = 1; } ''', r''' class C { final int f; const C() : f = 2; } ''', ); } test_class_constructor_initializer_empty() { _assertNotSameSignature( r''' class C { C.foo() : ; // ^ // [diag.missingInitializer] Expected an initializer. } ''', r''' class C { C.foo() : f; // ^ // [diag.missingAssignmentInInitializer] Expected an assignment after the field name. } ''', ); } /// See https://github.com/dart-lang/sdk/issues/46206 test_class_constructor_initializer_notConst() { _assertNotSameSignature( r''' class C { final int f; C.foo() : f = 1; const C.bar(); } ''', r''' class C { final int f; C.foo() : f = 2; const C.bar(); } ''', ); } test_class_constructor_parameters_add() { _assertNotSameSignature( r''' class C { C(int a); } ''', r''' class C { C(int a, int b); } ''', ); } test_class_constructor_parameters_remove() { _assertNotSameSignature( r''' class C { C(int a, int b); } ''', r''' class C { C(int a); } ''', ); } test_class_constructor_parameters_rename() { _assertNotSameSignature( r''' class C { C(int a); } ''', r''' class C { C(int b); } ''', ); } test_class_constructor_parameters_type() { _assertNotSameSignature( r''' class C { C(int p); } ''', r''' class C { C(double p); } ''', ); } test_class_constructor_redirectedConstructor_const() { _assertNotSameSignature( r''' class A { const factory A() = B.foo; } class B implements A { const B.foo(); const B.bar(); } ''', r''' class A { const factory A() = B.bar; } class B implements A { const B.foo(); const B.bar(); } ''', ); } test_class_constructor_redirectedConstructor_notConst() { _assertNotSameSignature( r''' class A { factory A() = B.foo; } class B implements A { B.foo(); B.bar(); } ''', r''' class A { factory A() = B.bar; } class B implements A { B.foo(); B.bar(); } ''', ); } test_class_documentation_add() async { _assertSameSignature( r''' class C {} ''', r''' /// foo class C {} ''', ); } test_class_documentation_change() async { _assertSameSignature( r''' /// foo class C {} ''', r''' /// bar bar class C {} ''', ); } test_class_documentation_remove() async { _assertSameSignature( r''' /// foo class C {} ''', r''' class C {} ''', ); } test_class_emptyBody() { _assertSameSignature( r''' class C; ''', r''' class C; ''', ); } test_class_extends() { _assertNotSameSignature( r''' class A {} class B {} ''', r''' class A {} class B extends A {} ''', ); } /// The code `=;` is parsed as `= ;`, and there was a bug that /// the absence of the redirecting constructor was encoded as the same /// byte sequence as the empty string. But these are different ASTs, /// so they should have different signatures. test_class_factoryConstructor_addEqNothing() { _assertNotSameSignature( r''' class A { factory A(); } ''', r''' class A { factory A() =; // ^ // [diag.missingIdentifier] Expected an identifier. } ''', ); } test_class_factoryConstructor_block_to_block_differentStatement() { _assertSameSignature( r''' class A { factory A() { var v = 1; } } ''', r''' class A { factory A() { var v = 2; } } ''', ); } test_class_factoryConstructor_block_to_block_identical() { _assertSameSignature( r''' class A { factory A() { var v = 1; } } ''', r''' class A { factory A() { var v = 1; } } ''', ); } test_class_factoryConstructor_block_to_empty() { _assertNotSameSignature( r''' class A { factory A() {} } ''', r''' class A { factory A(); } ''', ); } test_class_factoryConstructor_empty_to_block() { _assertNotSameSignature( r''' class A { factory A(); } ''', r''' class A { factory A() {} } ''', ); } test_class_factoryConstructor_empty_to_empty() { _assertSameSignature( r''' class A { factory A(); } ''', r''' class A { factory A(); } ''', ); } /// The token `static` is moving from the field declaration to the factory /// constructor (its redirected constructor), so semantically its meaning /// changes. But we had a bug that we put `static` into the signature /// at the same position, without any separator, so failed to see the /// difference. test_class_factoryConstructor_empty_to_eq() { _assertNotSameSignature( r''' class A { factory A(); static void foo() {} } ''', r''' class A { factory A() = static void foo() {} //^^^^^^ // [diag.expectedToken] Expected to find ';'. } ''', ); } test_class_field_augment_add() { _assertNotSameSignature( r''' augment class A { int foo = 42; } ''', r''' augment class A { augment int foo = 42; } ''', ); } test_class_field_augment_remove() { _assertNotSameSignature( r''' augment class A { augment int foo = 42; } ''', r''' augment class A { int foo = 42; } ''', ); } test_class_field_const_add_outOfOrder() { _assertNotSameSignature( r''' class A { static f = Object(); // ^ // [diag.missingConstFinalVarOrType] Variables must be declared using the keywords 'const', 'final', 'var' or a type name. } ''', r''' class A { const static f = Object(); //^^^^^^ // [diag.modifierOutOfOrder] The modifier 'static' should be before the modifier 'const'. } ''', ); } test_class_field_withType_final_hasConstConstructor() { _assertNotSameSignature( r''' class C { final int a = 1; const C(); } ''', r''' class C { final int a = 2; const C(); } ''', ); } test_class_field_withType_final_noConstConstructor() { _assertSameSignature( r''' final int a = 1; ''', r''' final int a = 2; ''', ); } test_class_field_withType_hasConstConstructor() { _assertSameSignature( r''' class C { int a = 1; const C(); } ''', r''' class C { int a = 2; const C(); } ''', ); } test_class_field_withType_static_final_hasConstConstructor() { _assertSameSignature( r''' class C { static final int a = 1; const C(); } ''', r''' class C { static final int a = 2; const C(); } ''', ); } test_class_field_withType_static_hasConstConstructor() { _assertSameSignature( r''' class C { static int a = 1; const C(); } ''', r''' class C { static int a = 2; const C(); } ''', ); } test_class_implements() { _assertNotSameSignature( r''' class A {} class B {} ''', r''' class A {} 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 {} ''', r''' abstract class C {} ''', ); } test_class_primaryConstructorBody_body() { _assertSameSignature( r''' class C() { this { 0; } } ''', r''' class C() { this { 1; } } ''', ); } test_class_primaryConstructorBody_initializer_const() { _assertNotSameSignature( r''' class const C() { final int f; this: f = 1; } ''', r''' class const C() { final int f; this: f = 2; } ''', ); } test_class_primaryConstructorBody_metadata() { _assertNotSameSignature( r''' class C() { this; } ''', r''' class C() { @deprecated this; } ''', ); } test_class_with() { _assertNotSameSignature( r''' class A {} class B {} class C extends A {} ''', r''' class A {} class B {} class C extends A with B {} ''', ); } test_classLike_field_const_add_outOfOrder_hasFinal() { _assertNotSameSignature_classLike( r''' static final f = Object(); ''', r''' const static final f = Object(); // [diag.modifierOutOfOrder][column 1][length 6] The modifier 'static' should be before the modifier 'const'. // ^^^^^ // [diag.constAndFinal] Members can't be declared to be both 'const' and 'final'. ''', ); } test_classLike_field_final_add() { _assertNotSameSignature_classLike( r''' int a = 0; ''', r''' final int a = 0; ''', ); } test_classLike_field_late_add() { _assertNotSameSignature_classLike( r''' int a; ''', r''' late int a; ''', ); } test_classLike_field_late_remove() { _assertNotSameSignature_classLike( r''' late int a; ''', r''' int a; ''', ); } test_classLike_field_static_add() { _assertNotSameSignature_classLike( r''' int a; ''', r''' static int a; ''', ); } test_classLike_field_withoutType() { _assertNotSameSignature_classLike( r''' var a = 1; ''', r''' var a = 2; ''', ); } test_classLike_field_withoutType2() { _assertNotSameSignature_classLike( r''' var a = 1, b = 2, c, d = 4; ''', r''' var a = 1, b, c = 3, d = 4; ''', ); } test_classLike_field_withType() { _assertSameSignature_classLike( r''' int a = 1; ''', r''' int a = 2; ''', ); } test_classLike_field_withType_const() { _assertNotSameSignature_classLike( r''' static const int a = 1; ''', r''' static const int a = 2; ''', ); } test_classLike_method_body_block_invokesSuperSelf_falseToTrue() { _assertNotSameSignature_classLike( r''' void foo() {} ''', r''' void foo() { super.foo(); } ''', ); } test_classLike_method_body_block_invokesSuperSelf_trueToFalse_assignmentExpression() { _assertNotSameSignature_classLike( r''' set foo(int _) { super.foo = 0; } ''', r''' set foo(int _) {} ''', ); } test_classLike_method_body_block_invokesSuperSelf_trueToFalse_binaryExpression() { _assertNotSameSignature_classLike( r''' int operator +() { super + 2; return 0; } ''', r''' int operator +() { return 0; } ''', ); } test_classLike_method_body_block_invokesSuperSelf_trueToFalse_differentName() { _assertNotSameSignature_classLike( r''' void foo() { super.foo(); } ''', r''' void foo() { super.bar(); } ''', ); } test_classLike_method_body_block_invokesSuperSelf_trueToFalse_methodInvocation() { _assertNotSameSignature_classLike( r''' void foo() { super.foo(); } ''', r''' void foo() {} ''', ); } test_classLike_method_body_block_invokesSuperSelf_trueToFalse_propertyAccess() { _assertNotSameSignature_classLike( r''' void foo() { super.foo; } ''', r''' void foo() {} ''', ); } test_classLike_method_body_block_to_empty() { _assertNotSameSignature_classLike( r''' void foo() {} ''', r''' void foo(); ''', ); } test_classLike_method_body_empty_to_block() { _assertNotSameSignature_classLike( r''' void foo(); ''', r''' void foo() {} ''', ); } test_classLike_method_body_empty_to_expression() { _assertNotSameSignature_classLike( r''' int foo(); ''', r''' int foo() => 0; ''', ); } test_classLike_method_body_expression_invokesSuperSelf_trueToFalse_methodInvocation() { _assertNotSameSignature_classLike( r''' void foo() => super.foo(); ''', r''' void foo() => 0; ''', ); } test_classLike_method_external_to_block() { _assertNotSameSignature_classLike( r''' external void foo(); ''', r''' void foo() {} ''', ); } test_classLike_method_getter_body_block_to_empty() { _assertNotSameSignature_classLike( r''' int get foo { return 1; } ''', r''' int get foo; ''', ); } test_classLike_method_getter_body_empty_to_block() { _assertNotSameSignature_classLike( r''' int get foo; ''', r''' int get foo { return 0; } ''', ); } test_classLike_method_getter_body_empty_to_expression() { _assertNotSameSignature_classLike( r''' int get foo; ''', r''' int get foo => 0; ''', ); } test_classLike_method_getter_body_expression_to_empty() { _assertNotSameSignature_classLike( r''' int get foo => 0; ''', r''' int get foo; ''', ); } test_classLike_method_setter_body_block_to_empty() { _assertNotSameSignature_classLike( r''' set foo(_) {} ''', r''' set foo(_); ''', ); } test_classLike_method_setter_body_empty_to_block() { _assertNotSameSignature_classLike( r''' set foo(_); ''', r''' set foo(_) {} ''', ); } test_commentAdd() { _assertSameSignature( r''' var a = 1; var b = 2; var c = 3; ''', r''' var a = 1; // comment /// comment 1 /// comment 2 var b = 2; /** * Comment */ var c = 3; ''', ); } test_commentRemove() { _assertSameSignature( r''' var a = 1; // comment /// comment 1 /// comment 2 var b = 2; /** * Comment */ var c = 3; ''', r''' var a = 1; var b = 2; var c = 3; ''', ); } test_directive_library_add() { _assertNotSameSignature( r''' class A {} ''', r''' library foo; class A {} ''', ); } test_directive_library_change_name() { _assertNotSameSignature( r''' library foo; class A {} ''', r''' library bar; class A {} ''', ); } test_directive_library_change_name_length() { _assertSameSignature( r''' library foo.bar; class A {} ''', r''' library foo. bar; class A {} ''', ); } test_directive_library_change_name_offset() { _assertSameSignature( r''' library foo; class A {} ''', r''' library foo; class A {} ''', ); } test_directive_library_remove() { _assertNotSameSignature( r''' library foo; class A {} ''', r''' class A {} ''', ); } test_enum_emptyBody() { _assertSameSignature( r''' enum E; ''', r''' enum E; ''', ); } test_enum_enumConstants_add() { _assertNotSameSignature( r''' enum E { v } ''', r''' enum E { v, v2 } ''', ); } test_enum_enumConstants_add_hasMethod() { _assertNotSameSignature( r''' enum E { v; void foo() {} } ''', r''' enum E { v, v2; void foo() {} } ''', ); } test_enum_enumConstants_constructorArguments_add() { _assertNotSameSignature( r''' enum E { v; E({int? a}); } ''', r''' enum E { v(a: 0); E({int? a}); } ''', ); } test_enum_enumConstants_constructorArguments_change() { _assertNotSameSignature( r''' enum E { v(0); E(int a); } ''', r''' enum E { v(1); E(int a); } ''', ); } test_enum_enumConstants_constructorArguments_remove() { _assertNotSameSignature( r''' enum E { v(a: 0); E({int? a}); } ''', r''' enum E { v; E({int? a}); } ''', ); } test_enum_enumConstants_remove() { _assertNotSameSignature( r''' enum E { v, v2 } ''', r''' enum E { v } ''', ); } test_enum_enumConstants_rename() { _assertNotSameSignature( r''' enum E { v } ''', r''' enum E { v2 } ''', ); } test_enum_field_withType_final() { _assertNotSameSignature( r''' enum E { v; final int a = 1; } ''', r''' enum E { v; final int a = 2; } ''', ); } test_enum_implements_add() { _assertNotSameSignature( r''' class A {} enum E { v } ''', r''' class A {} enum E implements A { v } ''', ); } test_enum_implements_change() { _assertNotSameSignature( r''' class A {} class B {} enum E implements A { v } ''', r''' class A {} class B {} enum E implements B { v } ''', ); } test_enum_implements_remove() { _assertNotSameSignature( r''' class A {} enum E implements A { v } ''', r''' class A {} enum E { v } ''', ); } test_enum_metadata_add() { _assertNotSameSignature( r''' enum E { v } ''', r''' @a enum E { v } ''', ); } test_enum_typeParameters_add() { _assertNotSameSignature( r''' enum E { v } ''', r''' enum E { v } ''', ); } test_enum_typeParameters_remove() { _assertNotSameSignature( r''' enum E { v } ''', r''' enum E { v } ''', ); } test_enum_typeParameters_rename() { _assertNotSameSignature( r''' enum E { v } ''', r''' enum E { v } ''', ); } test_enum_with_add() { _assertNotSameSignature( r''' mixin M {} enum E { v } ''', r''' mixin M {} enum E with M { v } ''', ); } test_enum_with_change() { _assertNotSameSignature( r''' mixin M1 {} mixin M2 {} enum E with M1 { v } ''', r''' mixin M1 {} mixin M2 {} enum E with M2 { v } ''', ); } test_enum_with_remove() { _assertNotSameSignature( r''' mixin M {} enum E with M { v } ''', r''' mixin M {} enum E { v } ''', ); } test_executable_annotation() { _assertNotSameSignature_executable( r''' void foo() {} ''', r''' @a void foo() {} ''', ); } test_executable_body_async_to_asyncStar() { _assertNotSameSignature_executable( r''' foo() async {} ''', r''' foo() async* {} ''', ); } test_executable_body_async_to_sync() { _assertNotSameSignature_executable( r''' foo() async {} ''', r''' foo() {} ''', ); } test_executable_body_asyncStar_to_async() { _assertNotSameSignature_executable( r''' foo() async* {} ''', r''' foo() async {} ''', ); } test_executable_body_asyncStar_to_syncStar() { _assertNotSameSignature_executable( r''' foo() async* {} ''', r''' foo() sync* {} ''', ); } test_executable_body_block() { _assertSameSignature_executable( r''' int foo() { return 1; } ''', r''' int foo() { return 2; } ''', ); } test_executable_body_block_to_expression() { _assertSameSignature_executable( r''' int foo() { return 1; } ''', r''' int foo() => 2; ''', ); } test_executable_body_block_to_external() { _assertNotSameSignature_executable( r''' void foo() {} ''', r''' external void foo(); ''', ); } test_executable_body_block_to_native() { _assertNotSameSignature_executable( r''' int foo() { return 0; } ''', r''' int foo() native; ''', ); } test_executable_body_expression() { _assertSameSignature_executable( r''' int foo() => 1; ''', r''' int foo() => 2; ''', ); } test_executable_body_expression_to_block() { _assertSameSignature_executable( r''' int foo() => 1; ''', r''' int foo() { return 2; } ''', ); } test_executable_body_expression_to_native() { _assertNotSameSignature_executable( r''' int foo() => 0; ''', r''' int foo() native; ''', ); } test_executable_body_external_to_block() { _assertNotSameSignature_executable( r''' external void foo(); ''', r''' void foo() {} ''', ); } test_executable_body_native_to_block() { _assertNotSameSignature_executable( r''' int foo() native; ''', r''' int foo() { return 0; } ''', ); } test_executable_body_native_to_expression() { _assertNotSameSignature_executable( r''' int foo() native; ''', r''' int foo() => 0; ''', ); } test_executable_body_sync_to_async() { _assertNotSameSignature_executable( r''' foo() {} ''', r''' foo() async {} ''', ); } test_executable_body_sync_to_syncStar() { _assertNotSameSignature_executable( r''' foo() sync* {} ''', r''' foo() {} ''', ); } test_executable_body_syncStar_to_sync() { _assertNotSameSignature_executable( r''' foo() sync* {} ''', r''' foo() {} ''', ); } test_executable_getter_body_block_to_expression() { _assertSameSignature_executable( r''' int get foo { return 1; } ''', r''' int get foo => 2; ''', ); } test_executable_getter_body_expression_to_block() { _assertSameSignature_executable( r''' int get foo => 1; ''', r''' int get foo { return 2; } ''', ); } test_executable_parameters_add() { _assertNotSameSignature_executable( r''' foo(int a) {} ''', r''' foo(int a, int b) {} ''', ); } test_executable_parameters_remove() { _assertNotSameSignature_executable( r''' foo(int a, int b) {} ''', r''' foo(int a) {} ''', ); } test_executable_parameters_rename() { _assertNotSameSignature_executable( r''' void foo(int a) {} ''', r''' void foo(int b) {} ''', ); } test_executable_parameters_type() { _assertNotSameSignature_executable( r''' void foo(int p) {} ''', r''' void foo(double p) {} ''', ); } test_executable_returnType() { _assertNotSameSignature_executable( r''' int foo() => 0; ''', r''' num foo() => 0; ''', ); } test_executable_typeParameters_add() async { _assertNotSameSignature_executable( r''' void foo() {} ''', r''' void foo() {} ''', ); } test_executable_typeParameters_remove() { _assertNotSameSignature_executable( r''' void foo() {} ''', r''' void foo() {} ''', ); } test_executable_typeParameters_rename() { _assertNotSameSignature_executable( r''' void foo() {} ''', r''' void foo() {} ''', ); } test_extension_emptyBody() { _assertSameSignature( r''' extension E on int; ''', r''' extension E on int; ''', ); } test_extension_on() { _assertNotSameSignature( r''' extension E on int {} ''', r''' extension E on num {} ''', ); } test_extension_typeParameter_add() { _assertNotSameSignature( r''' extension E on int {} ''', r''' extension E on int {} ''', ); } test_extension_typeParameter_remove() { _assertNotSameSignature( r''' extension E on int {} ''', r''' extension E on int {} ''', ); } test_extension_typeParameter_rename() { _assertNotSameSignature( r''' extension E on int {} ''', r''' extension E on int {} ''', ); } test_featureSet_add() async { _assertNotSameSignature( r''' class A {} ''', r''' // @dart = 3.2 class A {} ''', ); } test_featureSet_change() async { _assertNotSameSignature( r''' // @dart = 3.2 class A {} ''', r''' // @dart = 3.3 class A {} ''', ); } test_featureSet_remove() async { _assertNotSameSignature( r''' // @dart = 3.2 class A {} ''', r''' class A {} ''', ); } test_issue34850() { _assertNotSameSignature( r''' foo Future> bar() {} // [diag.missingFunctionParameters][column 1][length 6] Functions must have an explicit list of parameters. // ^^^^ // [diag.expectedToken] Expected to find '>'. // ^^^ // [diag.missingFunctionBody] A function body must be provided. ''', r''' foo Future> bar(int x) {} // [diag.missingFunctionParameters][column 1][length 6] Functions must have an explicit list of parameters. // ^^^^ // [diag.expectedToken] Expected to find '>'. // ^^^ // [diag.missingFunctionBody] A function body must be provided. ''', ); } test_mixin_emptyBody() { _assertSameSignature( r''' mixin M; ''', r''' mixin M; ''', ); } test_mixin_field_withoutType() { _assertNotSameSignature( r''' mixin M { var a = 1; } ''', r''' mixin M { var a = 2; } ''', ); } test_mixin_field_withType() { _assertSameSignature( r''' mixin M { int a = 1; } ''', r''' mixin M { int a = 2; } ''', ); } test_mixin_implements() { _assertNotSameSignature( r''' class A {} mixin M {} ''', r''' class A {} mixin M implements A {} ''', ); } test_mixin_method_body_block() { _assertSameSignature( r''' mixin M { int foo() { return 1; } } ''', r''' mixin M { int foo() { return 2; } } ''', ); } test_mixin_method_body_expression() { _assertSameSignature( r''' mixin M { int foo() => 1; } ''', r''' mixin M { int foo() => 2; } ''', ); } test_mixin_on() { _assertNotSameSignature( r''' class A {} mixin M {} ''', r''' class A {} 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_indexRead_compoundAssignment() { _assertNotSameSignature( r''' mixin M { void foo() { super[0] = 0; } } ''', r''' mixin M { void foo() { super[0] += 0; } } ''', ); } test_mixin_superInvokedNames_indexRead_ifNullAssignment() { _assertNotSameSignature( r''' mixin M { void foo() { super[0] = 0; } } ''', r''' mixin M { void foo() { super[0] ??= 0; } } ''', ); } test_mixin_superInvokedNames_indexRead_postfixIncrement() { _assertNotSameSignature( r''' mixin M { void foo() { super[0] = 0; } } ''', r''' mixin M { void foo() { super[0]++; } } ''', ); } test_mixin_superInvokedNames_indexRead_prefixIncrement() { _assertNotSameSignature( r''' mixin M { void foo() { super[0] = 0; } } ''', r''' mixin M { void foo() { ++super[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_topLevelFunction_body_block_to_empty() { _assertNotSameSignature( r''' int foo() { return 0; } ''', r''' int foo(); ''', ); } test_topLevelFunction_body_empty_to_block() { _assertNotSameSignature( r''' int foo(); ''', r''' int foo() { return 0; } ''', ); } test_topLevelVariable_abstract_add() { _assertNotSameSignature( r''' int foo; ''', r''' abstract int foo; ''', ); } test_topLevelVariable_abstract_remove() { _assertNotSameSignature( r''' abstract int foo; ''', r''' int foo; ''', ); } test_topLevelVariable_augment_add() { _assertNotSameSignature( r''' int a = 0; ''', r''' augment int a = 0; ''', ); } test_topLevelVariable_augment_remove() { _assertNotSameSignature( r''' augment int a = 0; ''', r''' int a = 0; ''', ); } test_topLevelVariable_final_add() { _assertNotSameSignature( r''' int a = 0; ''', r''' final int a = 0; ''', ); } test_topLevelVariable_late_add() { _assertNotSameSignature( r''' int a; ''', r''' late int a; ''', ); } test_topLevelVariable_late_remove() { _assertNotSameSignature( r''' late int a; ''', r''' int a; ''', ); } test_topLevelVariable_withoutType() { _assertNotSameSignature( r''' var a = 1; ''', r''' var a = 2; ''', ); } test_topLevelVariable_withoutType2() { _assertNotSameSignature( r''' var a = 1, b = 2, c, d = 4; ''', r''' var a = 1, b, c = 3, d = 4; ''', ); } test_topLevelVariable_withType() { _assertSameSignature( r''' int a = 1; ''', r''' int a = 2; ''', ); } test_topLevelVariable_withType_const() { _assertNotSameSignature( r''' const int a = 1; ''', r''' const int a = 2; ''', ); } test_topLevelVariable_withType_final() { _assertSameSignature( r''' final int a = 1; ''', r''' final int a = 2; ''', ); } test_topLevelVariable_withType_initializer_add() { _assertNotSameSignature( r''' int a; ''', r''' int a = 1; ''', ); } test_topLevelVariable_withType_initializer_remove() { _assertNotSameSignature( r''' int a = 1; ''', r''' int a; ''', ); } test_typedef_generic_parameters_type() { _assertNotSameSignature( r''' typedef F = void Function(int); ''', r''' typedef F = void Function(double); ''', ); } void _assertNotSameSignature(String oldCode, String newCode) { _assertSignature(oldCode, newCode, same: false); } void _assertNotSameSignature_classLike(String oldCode, String newCode) { _assertSignature_classLike(oldCode, newCode, same: false); } void _assertNotSameSignature_executable(String oldCode, String newCode) { _assertSignature_executable(oldCode, newCode, same: false); } void _assertSameSignature(String oldCode, String newCode) { _assertSignature(oldCode, newCode, same: true); } void _assertSameSignature_classLike(String code1, String code2) { _assertSignature_classLike(code1, code2, same: true); } void _assertSameSignature_executable(String oldCode, String newCode) { _assertSignature_executable(oldCode, newCode, same: true); } void _assertSignature(String oldCode, String newCode, {required bool same}) { var oldResult = parseTestCodeWithDiagnostics(oldCode); var oldUnit = oldResult.unit as CompilationUnitImpl; var oldSignature = computeUnlinkedApiSignature(oldUnit); var newResult = parseTestCodeWithDiagnostics(newCode); var newUnit = newResult.unit as CompilationUnitImpl; var newSignature = computeUnlinkedApiSignature(newUnit); if (same) { expect(newSignature, oldSignature); } else { expect(newSignature, isNot(oldSignature)); } } void _assertSignature_classLike( String oldCode, String newCode, { required bool same, }) { _assertSignature( ''' class A { $oldCode } ''', ''' class A { $newCode } ''', same: same, ); _assertSignature( ''' extension on int { $oldCode } ''', ''' extension on int { $newCode } ''', same: same, ); _assertSignature( ''' mixin M { $oldCode } ''', ''' mixin M { $newCode } ''', same: same, ); _assertSignature( ''' enum E { v; $oldCode } ''', ''' enum E { v; $newCode } ''', same: same, ); } void _assertSignature_executable( String oldCode, String newCode, { required bool same, }) { _assertSignature_classLike(oldCode, newCode, same: same); _assertSignature(oldCode, newCode, same: same); } }