Class modifiers changes for mock SDK, fixes for analyzer, analysis_server tests.

Some of these changes were in the flip CL.
https://dart-review.googlesource.com/c/sdk/+/285080

Change-Id: I3f9d7905aeaedc25f2008410a2b48ff74ef2d74f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287420
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-03-08 18:31:31 +00:00 committed by Commit Queue
parent 4733f9b754
commit 424d56f34c
21 changed files with 299 additions and 57 deletions

View file

@ -12,11 +12,14 @@ class B extends Function {}
/*cfe|cfe:builder.class: C:C,Object,_C&Object&Function*/
/*analyzer.class: C:C,Object*/
class C extends Object with Function {}
class C extends Object
with /*analyzer.error: CompileTimeErrorCode.CLASS_USED_AS_MIXIN*/
Function {}
// CFE hides that this is a mixin declaration since its mixed in type has been
// removed.
/*cfe|cfe:builder.class: _C&Object&Function:Object,_C&Object&Function*/
/*cfe|cfe:builder.class: D:D,Object*/
class D = Object with Function;
class D = Object
with /*analyzer.error: CompileTimeErrorCode.CLASS_USED_AS_MIXIN*/ Function;

View file

@ -510,9 +510,9 @@ CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR:
CompileTimeErrorCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE:
status: needsEvaluation
CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY:
status: needsEvaluation
status: hasFix
CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY:
status: needsEvaluation
status: hasFix
CompileTimeErrorCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR:
status: needsEvaluation
CompileTimeErrorCode.FINAL_MIXIN_IMPLEMENTED_OUTSIDE_OF_LIBRARY:

View file

@ -1008,6 +1008,12 @@ class FixProcessor extends BaseProcessor {
CreateConstructor.new,
ConvertToNamedArguments.new,
],
CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY: [
RemoveNameFromDeclarationClause.new,
],
CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY: [
RemoveNameFromDeclarationClause.new,
],
CompileTimeErrorCode.FINAL_NOT_INITIALIZED: [
AddLate.new,
CreateConstructorForFinalFields.new,

View file

@ -47,7 +47,7 @@ mixin EnumDeclarationTestCases on AbstractCompletionDriverTest {
@override
Future<void> setUp() async {
await super.setUp();
allowedIdentifiers = const {'Object', 'foo01', 'foo02', 'new'};
allowedIdentifiers = const {'Object', 'foo01', 'foo02', 'new', 'A01'};
}
Future<void> test_afterConstants_noSemicolon() async {
@ -177,16 +177,28 @@ suggestions
Future<void> test_afterWith() async {
await computeSuggestions('''
mixin class A01 {}
enum E with ^ {
v
}
''');
assertResponse('''
if (isProtocolVersion2) {
assertResponse('''
suggestions
A01
kind: class
''');
} else {
assertResponse('''
suggestions
A01
kind: class
Object
kind: class
''');
}
}
Future<void> test_afterWithClause() async {

View file

@ -103,17 +103,17 @@ class B01 {}
assertResponse('''
suggestions
A01
kind: class
kind: constructorInvocation
A01
kind: constructorInvocation
kind: class
A02
kind: constructorInvocation
A02
kind: class
B01
kind: constructorInvocation
B01
kind: class
B01
kind: constructorInvocation
const
kind: keyword
dynamic

View file

@ -4,6 +4,7 @@
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/src/dart/error/ffi_code.g.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@ -54,9 +55,13 @@ class ExtendsDisallowedClassTest extends FixProcessorTest {
await resolveTestCode('''
class C extends String {}
''');
await assertHasFix('''
await assertHasFix(
'''
class C {}
''');
''',
errorFilter: (error) =>
error.errorCode == CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
);
}
}
@ -101,18 +106,26 @@ class ImplementsDisallowedClassTest extends FixProcessorTest {
await resolveTestCode('''
class C implements String {}
''');
await assertHasFix('''
await assertHasFix(
'''
class C {}
''');
''',
errorFilter: (error) =>
error.errorCode == CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
);
}
Future<void> test_twoNames() async {
await resolveTestCode('''
abstract class C implements String, List<int> {}
''');
await assertHasFix('''
await assertHasFix(
'''
abstract class C implements List<int> {}
''');
''',
errorFilter: (error) =>
error.errorCode == CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
);
}
}
@ -176,9 +189,13 @@ class MixinOfDisallowedClassTest extends FixProcessorTest {
await resolveTestCode('''
abstract class C with String {}
''');
await assertHasFix('''
await assertHasFix(
'''
abstract class C {}
''');
''',
errorFilter: (error) =>
error.errorCode == CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
);
}
}

View file

@ -1696,6 +1696,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// Verifies that the class is not named `Function` and that it doesn't
/// extends/implements/mixes in `Function`.
void _checkForBadFunctionUse(ClassDeclaration node) {
// With the `class_modifiers` feature `Function` is final.
if (_featureSet!.isEnabled(Feature.class_modifiers)) {
return;
}
var extendsClause = node.extendsClause;
var implementsClause = node.implementsClause;
var withClause = node.withClause;

View file

@ -168,7 +168,7 @@ abstract class HashMap<K, V> implements Map<K, V> {
}
}
abstract class IterableMixin<E> implements Iterable<E> { }
abstract mixin class IterableMixin<E> implements Iterable<E> { }
abstract class LinkedHashMap<K, V> implements Map<K, V> {
external factory LinkedHashMap(
@ -218,11 +218,11 @@ abstract class LinkedHashSet<E> implements Set<E> {
}
}
abstract class ListMixin<E> implements List<E> { }
abstract mixin class ListMixin<E> implements List<E> { }
abstract class MapMixin<K, V> implements Map<K, V> { }
abstract mixin class MapMixin<K, V> implements Map<K, V> { }
abstract class SetMixin<E> implements Set<E> { }
abstract mixin class SetMixin<E> implements Set<E> { }
abstract class Queue<E> implements Iterable<E> {
bool remove(Object? value);
@ -256,7 +256,7 @@ class JsonCodec {
abstract class StringConversionSink { }
abstract class StringConversionSinkMixin implements StringConversionSink { }
abstract mixin class StringConversionSinkMixin implements StringConversionSink { }
''',
)
],
@ -297,7 +297,7 @@ class BigInt implements Comparable<BigInt> {
static BigInt parse(String source, {int? radix}) => throw 0;
}
abstract class bool extends Object {
abstract final class bool extends Object {
external const factory bool.fromEnvironment(String name,
{bool defaultValue = false});
@ -338,7 +338,7 @@ class pragma {
const pragma(this.name, [this.options]);
}
abstract class double extends num {
abstract final class double extends num {
static const double nan = 0.0 / 0.0;
static const double infinity = 1.0 / 0.0;
static const double negativeInfinity = -infinity;
@ -402,9 +402,9 @@ class Exception {
class FormatException implements Exception {}
class Function {}
abstract final class Function {}
abstract class int extends num {
abstract final class int extends num {
external const factory int.fromEnvironment(String name,
{int defaultValue = 0});
@ -534,7 +534,7 @@ abstract class Map<K, V> {
V? remove(Object? key);
}
class Null extends Object {
final class Null extends Object {
factory Null._uninstantiable() {
throw 0;
}
@ -547,7 +547,7 @@ class MapEntry<K, V> {
const MapEntry._(this.key, this.value);
}
abstract class num implements Comparable<num> {
sealed class num implements Comparable<num> {
num operator %(num other);
num operator *(num other);
num operator +(num other);
@ -604,7 +604,7 @@ abstract class Pattern {
Iterable<Match> allMatches(String string, [int start = 0]);
}
abstract class Record {}
abstract final class Record {}
abstract class RegExp implements Pattern {
external factory RegExp(String source, {bool unicode = false});
@ -638,7 +638,7 @@ abstract class Sink {
class StackTrace {}
abstract class String implements Comparable<String>, Pattern {
abstract final class String implements Comparable<String>, Pattern {
external factory String.fromCharCodes(Iterable<int> charCodes,
[int start = 0, int? end]);
@ -1397,8 +1397,10 @@ void createMockSdk({
json.encode({
'version': 1,
'experimentSets': {
'sdkExperiments': <String>[],
'nullSafety': ['non-nullable']
'sdkExperiments': <String>[
'class-modifiers',
'sealed-class',
],
},
'sdk': {
'default': {'experimentSet': 'sdkExperiments'},

View file

@ -45,30 +45,38 @@ class X = A with B implements C;
}
test_element_typeFunction_extends() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
mixin class A {}
class X = Function with A;
''');
''', [
error(
CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY, 27, 8),
]);
var x = findElement.class_('X');
assertType(x.supertype, 'Object');
}
test_element_typeFunction_implements() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
mixin class A {}
class B {}
class X = Object with A implements A, Function, B;
''');
''', [
error(CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY, 66,
8),
]);
var x = findElement.class_('X');
assertElementTypes(x.interfaces, ['A', 'B']);
}
test_element_typeFunction_with() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
mixin class A {}
mixin class B {}
class X = Object with A, Function, B;
''');
''', [
error(CompileTimeErrorCode.CLASS_USED_AS_MIXIN, 59, 8),
]);
var x = findElement.class_('X');
assertElementTypes(x.mixins, ['A', 'B']);
}

View file

@ -100,7 +100,19 @@ class X extends A {}
await assertErrorsInCode(r'''
class A extends Function {}
''', [
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 16, 8),
error(
CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY, 16, 8),
]);
var a = findElement.class_('A');
assertType(a.supertype, 'Object');
}
test_element_typeFunction_extends_language219() async {
await assertErrorsInCode(r'''
// @dart = 2.19
class A extends Function {}
''', [
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 32, 8),
]);
var a = findElement.class_('A');
assertType(a.supertype, 'Object');
@ -112,7 +124,24 @@ mixin A {}
mixin B {}
class C extends Object with A, Function, B {}
''', [
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 53, 8),
error(CompileTimeErrorCode.CLASS_USED_AS_MIXIN, 53, 8),
]);
assertElementTypes(
findElement.class_('C').mixins,
['A', 'B'],
);
}
test_element_typeFunction_with_language219() async {
await assertErrorsInCode(r'''
// @dart = 2.19
mixin A {}
mixin B {}
class C extends Object with A, Function, B {}
''', [
error(CompileTimeErrorCode.CLASS_USED_AS_MIXIN, 69, 8),
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 69, 8),
]);
assertElementTypes(

View file

@ -19,17 +19,28 @@ class DeprecatedExtendsFunctionTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A extends Function {}
''', [
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 16, 8),
error(
CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY, 16, 8),
]);
}
test_local() async {
test_core_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
class A extends Function {}
''', [
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 32, 8),
]);
}
test_local_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
class Function {}
class A extends Function {}
''', [
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8),
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 34, 8),
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 22, 8),
error(WarningCode.DEPRECATED_EXTENDS_FUNCTION, 50, 8),
]);
}
}

View file

@ -19,7 +19,8 @@ class DeprecatedImplementsFunctionTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A implements Function {}
''', [
error(WarningCode.DEPRECATED_IMPLEMENTS_FUNCTION, 19, 8),
error(CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY, 19,
8),
]);
}
@ -27,8 +28,30 @@ class A implements Function {}
await assertErrorsInCode('''
class A implements Function, Function {}
''', [
error(WarningCode.DEPRECATED_IMPLEMENTS_FUNCTION, 19, 8),
error(CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY, 19,
8),
error(CompileTimeErrorCode.IMPLEMENTS_REPEATED, 29, 8),
error(CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY, 29,
8),
]);
}
test_core2_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
class A implements Function, Function {}
''', [
error(WarningCode.DEPRECATED_IMPLEMENTS_FUNCTION, 35, 8),
error(CompileTimeErrorCode.IMPLEMENTS_REPEATED, 45, 8),
]);
}
test_core_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
class A implements Function {}
''', [
error(WarningCode.DEPRECATED_IMPLEMENTS_FUNCTION, 35, 8),
]);
}

View file

@ -19,7 +19,17 @@ class DeprecatedMixinFunctionTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A extends Object with Function {}
''', [
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 28, 8),
error(CompileTimeErrorCode.CLASS_USED_AS_MIXIN, 28, 8),
]);
}
test_core_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
class A extends Object with Function {}
''', [
error(CompileTimeErrorCode.CLASS_USED_AS_MIXIN, 44, 8),
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 44, 8),
]);
}
@ -29,7 +39,17 @@ mixin Function {}
class A extends Object with Function {}
''', [
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8),
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 46, 8),
]);
}
test_local_language219() async {
await assertErrorsInCode('''
// @dart = 2.19
mixin Function {}
class A extends Object with Function {}
''', [
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 22, 8),
error(WarningCode.DEPRECATED_MIXIN_FUNCTION, 62, 8),
]);
}
}

View file

@ -19,6 +19,11 @@ class ExtendsDisallowedClassTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A extends bool {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 16, 4),
]);
}
@ -27,6 +32,11 @@ class A extends bool {}
await assertErrorsInCode('''
class A extends double {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 16, 6),
]);
}
@ -72,6 +82,11 @@ class A<T> extends FutureOr<T> {}
await assertErrorsInCode('''
class A extends int {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 16, 3),
]);
}
@ -96,6 +111,11 @@ class A extends num {}
await assertErrorsInCode('''
class A extends Record {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 16, 6),
]);
}
@ -104,6 +124,11 @@ class A extends Record {}
await assertErrorsInCode('''
class A extends String {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 16, 6),
]);
}

View file

@ -19,6 +19,11 @@ class ImplementsDisallowedClassTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A implements bool {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 4),
]);
}
@ -51,6 +56,11 @@ class A implements Enum {}
await assertErrorsInCode('''
class A implements double {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 6),
]);
}
@ -96,6 +106,11 @@ class A<T> implements FutureOr<T> {}
await assertErrorsInCode('''
class A implements int {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 3),
]);
}
@ -120,6 +135,11 @@ class A implements num {}
await assertErrorsInCode('''
class A implements Record {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 6),
]);
}
@ -128,6 +148,11 @@ class A implements Record {}
await assertErrorsInCode('''
class A implements String {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 6),
]);
}
@ -136,6 +161,11 @@ class A implements String {}
await assertErrorsInCode('''
class A implements String, num {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 6),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 27, 3),
]);
@ -279,6 +309,11 @@ mixin M implements Enum {}
await assertErrorsInCode(r'''
mixin M implements int {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 19, 3),
]);

View file

@ -23,6 +23,7 @@ class InferenceFailureOnFunctionReturnTypeTest
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(
experiments: experiments,
strictInference: true,
),
);
@ -46,7 +47,7 @@ class C {
test_classInstanceMethod_overriding() async {
await assertNoErrorsInCode(r'''
class C {
mixin class C {
int f() => 7;
}

View file

@ -555,6 +555,8 @@ void f(num x) {
switch (x) {
case final int a || 2:
return;
default:
return;
}
}
''', [
@ -663,6 +665,8 @@ void f(num x) {
case final double a:
case 2:
return;
default:
return;
}
}
''', [
@ -709,6 +713,8 @@ void f(num x) {
return;
case 2:
return;
default:
return;
}
}
''', [

View file

@ -19,6 +19,11 @@ class MixinOfDisallowedClassTest extends PubPackageResolutionTest {
await assertErrorsInCode('''
class A extends Object with bool {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 28, 4),
]);
}
@ -27,6 +32,11 @@ class A extends Object with bool {}
await assertErrorsInCode('''
class A extends Object with double {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 28, 6),
]);
}
@ -62,6 +72,11 @@ class A<T> extends Object with FutureOr<T> {}
await assertErrorsInCode('''
class A extends Object with int {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 28, 3),
]);
}
@ -86,6 +101,11 @@ class A extends Object with num {}
await assertErrorsInCode('''
class A extends Object with Record {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 28, 6),
]);
}
@ -94,6 +114,11 @@ class A extends Object with Record {}
await assertErrorsInCode('''
class A extends Object with String {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 28, 6),
]);
}

View file

@ -46,6 +46,11 @@ mixin M on Enum {}
await assertErrorsInCode(r'''
mixin M on int {}
''', [
error(
CompileTimeErrorCode
.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED,
6,
1),
error(CompileTimeErrorCode.MIXIN_SUPER_CLASS_CONSTRAINT_DISALLOWED_CLASS,
11, 3),
]);

View file

@ -20,6 +20,7 @@ class StrictRawTypeTest extends PubPackageResolutionTest {
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(
experiments: experiments,
strictRawTypes: true,
),
);
@ -105,14 +106,16 @@ void f() {
test_mixinApplication_missing() async {
await assertErrorsInCode(r'''
class C<T> {}
mixin class C<T> {}
class D = Object with C;
''', [error(HintCode.STRICT_RAW_TYPE, 36, 1)]);
''', [
error(HintCode.STRICT_RAW_TYPE, 42, 1),
]);
}
test_mixinApplication_withTypeArg() async {
await assertNoErrorsInCode(r'''
class C<T> {}
mixin class C<T> {}
class D = Object with C<int>;
''');
}
@ -159,14 +162,16 @@ List f(int a) => [1, 2, 3];
test_superclassWith_missingTypeArg() async {
await assertErrorsInCode(r'''
class C<T> {}
mixin class C<T> {}
class D extends Object with C {}
''', [error(HintCode.STRICT_RAW_TYPE, 42, 1)]);
''', [
error(HintCode.STRICT_RAW_TYPE, 48, 1),
]);
}
test_superclassWith_withTypeArg() async {
await assertNoErrorsInCode(r'''
class C<T> {}
mixin class C<T> {}
class D extends Object with C<int> {}
''');
}
@ -252,7 +257,7 @@ F3 f3 = <T>(T a) => a;
await assertNoErrorsInCode(r'''
import 'package:meta/meta.dart';
@optionalTypeArgs
class C<T> {}
mixin class C<T> {}
class D extends C {}
class E extends Object with C {}
class F = Object with C;

View file

@ -45,6 +45,8 @@ class DocumentationValidator {
'CompileTimeErrorCode.DEFAULT_LIST_CONSTRUCTOR',
// The mock SDK doesn't define any internal libraries.
'CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY',
// Also reports CompileTimeErrorCode.SUBTYPE_OF_BASE_OR_FINAL_IS_NOT_BASE_FINAL_OR_SEALED
'CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS',
// Has code in the example section that needs to be skipped (because it's
// part of the explanatory text not part of the example), but there's
// currently no way to do that.
@ -120,6 +122,8 @@ class DocumentationValidator {
'PubspecWarningCode.PATH_PUBSPEC_DOES_NOT_EXIST',
'PubspecWarningCode.UNNECESSARY_DEV_DEPENDENCY',
// Reports CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY
'WarningCode.DEPRECATED_EXTENDS_FUNCTION',
// Produces more than one error range by design.
// TODO: update verification to allow for multiple highlight ranges.
'WarningCode.TEXT_DIRECTION_CODE_POINT_IN_COMMENT',