Skip to content

Commit 32a93e2

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Analyzer: Remove error on class-used-as-mixin referencing super
Fixes #34806 Change-Id: I1cfd0b9c0699734b172aa62f7a04ab533a6cd03f Fixed: 34806 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151099 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 3dc27a5 commit 32a93e2

File tree

9 files changed

+3
-120
lines changed

9 files changed

+3
-120
lines changed

pkg/analysis_server/test/integration/analysis/error_test.dart

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,6 @@ main() {
5151
});
5252
}
5353

54-
Future<void> test_super_mixins_disabled() async {
55-
var pathname = sourcePath('test.dart');
56-
writeFile(pathname, '''
57-
class Test extends Object with C {
58-
void foo() {}
59-
}
60-
abstract class B {
61-
void foo() {}
62-
}
63-
abstract class C extends B {
64-
void bar() {
65-
super.foo();
66-
}
67-
}
68-
''');
69-
standardAnalysisSetup();
70-
await analysisFinished;
71-
expect(currentAnalysisErrors[pathname], isList);
72-
var errors = currentAnalysisErrors[pathname];
73-
expect(errors, hasLength(2));
74-
var allErrorMessages = errors.map((AnalysisError e) => e.message).toSet();
75-
expect(
76-
allErrorMessages,
77-
contains(
78-
"The class 'C' can't be used as a mixin because it extends a class other than Object."));
79-
expect(
80-
allErrorMessages,
81-
contains(
82-
"The class 'C' can't be used as a mixin because it references 'super'."));
83-
}
84-
8554
@failingTest
8655
Future<void> test_super_mixins_enabled() async {
8756
// We see errors here with the new driver (#28870).

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ const List<ErrorCode> errorCodeValues = [
235235
CompileTimeErrorCode.MIXIN_INSTANTIATE,
236236
CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
237237
CompileTimeErrorCode.MIXIN_OF_NON_CLASS,
238-
CompileTimeErrorCode.MIXIN_REFERENCES_SUPER,
239238
CompileTimeErrorCode.MIXIN_SUPER_CLASS_CONSTRAINT_DEFERRED_CLASS,
240239
CompileTimeErrorCode.MIXIN_SUPER_CLASS_CONSTRAINT_DISALLOWED_CLASS,
241240
CompileTimeErrorCode.MIXIN_SUPER_CLASS_CONSTRAINT_NON_INTERFACE,

pkg/analyzer/lib/src/error/codes.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,16 +4135,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
41354135
'MIXIN_OF_NON_CLASS', "Classes can only mix in mixins and classes.",
41364136
hasPublishedDocs: true);
41374137

4138-
/**
4139-
* 9 Mixins: It is a compile-time error if a declared or derived mixin refers
4140-
* to super.
4141-
*/
4142-
static const CompileTimeErrorCode MIXIN_REFERENCES_SUPER =
4143-
CompileTimeErrorCode(
4144-
'MIXIN_REFERENCES_SUPER',
4145-
"The class '{0}' can't be used as a mixin because it references "
4146-
"'super'.");
4147-
41484138
static const CompileTimeErrorCode
41494139
MIXIN_SUPER_CLASS_CONSTRAINT_DEFERRED_CLASS = CompileTimeErrorCode(
41504140
'MIXIN_SUPER_CLASS_CONSTRAINT_DEFERRED_CLASS',

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
13011301
* Verify that all classes of the given [withClause] are valid.
13021302
*
13031303
* See [CompileTimeErrorCode.MIXIN_CLASS_DECLARES_CONSTRUCTOR],
1304-
* [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT], and
1305-
* [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER].
1304+
* [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT].
13061305
*/
13071306
bool _checkForAllMixinErrorCodes(WithClause withClause) {
13081307
if (withClause == null) {
@@ -1342,9 +1341,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
13421341
if (_checkForMixinInheritsNotFromObject(mixinName, mixinElement)) {
13431342
problemReported = true;
13441343
}
1345-
if (_checkForMixinReferencesSuper(mixinName, mixinElement)) {
1346-
problemReported = true;
1347-
}
13481344
}
13491345
}
13501346
}
@@ -3297,24 +3293,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
32973293
return false;
32983294
}
32993295

3300-
/**
3301-
* Verify that the given mixin does not reference 'super'. The [mixinName] is
3302-
* the node to report problem on. The [mixinElement] is the mixing to
3303-
* evaluate.
3304-
*
3305-
* See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER].
3306-
*/
3307-
bool _checkForMixinReferencesSuper(
3308-
TypeName mixinName, ClassElement mixinElement) {
3309-
if (mixinElement.hasReferenceToSuper) {
3310-
_errorReporter.reportErrorForNode(
3311-
CompileTimeErrorCode.MIXIN_REFERENCES_SUPER,
3312-
mixinName,
3313-
[mixinElement.name]);
3314-
}
3315-
return false;
3316-
}
3317-
33183296
/// Check that superclass constrains for the mixin type of [mixinName] at
33193297
/// the [mixinIndex] position in the mixins list are satisfied by the
33203298
/// [_enclosingClass], or a previous mixin.

pkg/analyzer/test/generated/simple_resolver_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,13 @@ class C = Object with A;''');
861861
}
862862

863863
test_isValidMixin_super() async {
864-
await assertErrorsInCode(r'''
864+
await assertNoErrorsInCode(r'''
865865
class A {
866866
toString() {
867867
return super.toString();
868868
}
869869
}
870-
class C = Object with A;''', [
871-
error(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, 82, 1),
872-
]);
870+
class C = Object with A;''');
873871
verifyTestResolved();
874872

875873
var a = findElement.class_('A');

pkg/analyzer/test/src/diagnostics/mixin_references_super_test.dart

Lines changed: 0 additions & 37 deletions
This file was deleted.

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ import 'mixin_inherits_from_not_object_test.dart'
293293
import 'mixin_of_disallowed_class_test.dart' as mixin_of_disallowed_class;
294294
import 'mixin_of_non_class_test.dart' as mixin_of_non_class;
295295
import 'mixin_on_sealed_class_test.dart' as mixin_on_sealed_class;
296-
import 'mixin_references_super_test.dart' as mixin_references_super;
297296
import 'mixin_super_class_constraint_non_interface_test.dart'
298297
as mixin_super_class_constraint_non_interface;
299298
import 'mixin_with_non_class_superclass_test.dart'
@@ -721,7 +720,6 @@ main() {
721720
mixin_of_disallowed_class.main();
722721
mixin_of_non_class.main();
723722
mixin_on_sealed_class.main();
724-
mixin_references_super.main();
725723
mixin_super_class_constraint_non_interface.main();
726724
mixin_with_non_class_superclass.main();
727725
must_be_a_native_function_type.main();

tests/language/mixin/illegal_super_use_test.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,8 @@ class P2 {
7676

7777
class C = Object with M;
7878
class D = Object with P0;
79-
// ^^
80-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8179
class E = Object with M, P1;
82-
// ^^
83-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8480
class F = Object with P2, M;
85-
// ^^
86-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8781

8882
main() {
8983
var p1 = new P1();

tests/language_2/mixin/illegal_super_use_test.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,8 @@ class P2 {
7676

7777
class C = Object with M;
7878
class D = Object with P0;
79-
// ^^
80-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8179
class E = Object with M, P1;
82-
// ^^
83-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8480
class F = Object with P2, M;
85-
// ^^
86-
// [analyzer] COMPILE_TIME_ERROR.MIXIN_REFERENCES_SUPER
8781

8882
main() {
8983
var p1 = new P1();

0 commit comments

Comments
 (0)