Skip to content

Commit 3b50e0a

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[cfe] Fix bug where we emit an extra error that we don't want for mixin classes.
Would otherwise emit `CantUseClassAsMixin` and then if the supertype is final or interface, would emit `FinalMixinMixedInOutsideOfLibrary` and `InterfaceMixinMixedInOutsideOfLibrary`respectively. These errors together don't make sense so this CL fixes it. Change-Id: I5fdf4e260b709e08af53cbda0414cff2ef93d3b5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286951 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent bd42ae8 commit 3b50e0a

12 files changed

+502
-3
lines changed

pkg/front_end/lib/src/fasta/source/source_loader.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,9 +2338,7 @@ severity: $severity
23382338
.withArguments(mixedInTypeDeclaration.fullNameForErrors),
23392339
mixedInTypeBuilder.charOffset ?? TreeNode.noOffset,
23402340
noLength);
2341-
}
2342-
2343-
if (cls.libraryBuilder.origin !=
2341+
} else if (cls.libraryBuilder.origin !=
23442342
mixedInTypeDeclaration.libraryBuilder.origin) {
23452343
if (mixedInTypeDeclaration.isInterface &&
23462344
!mayIgnoreClassModifiers(mixedInTypeDeclaration)) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'main_lib.dart';
6+
7+
class BaseWith with BaseClass {}
8+
9+
class InterfaceWith with InterfaceClass {}
10+
11+
class FinalWith with FinalClass {}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
6+
// class BaseWith with BaseClass {}
7+
// ^
8+
//
9+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
10+
// Try adding 'base', 'final', or 'sealed' to the type.
11+
// class BaseWith with BaseClass {}
12+
// ^
13+
//
14+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
15+
// class InterfaceWith with InterfaceClass {}
16+
// ^
17+
//
18+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
19+
// class FinalWith with FinalClass {}
20+
// ^
21+
//
22+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
23+
// Try adding 'base', 'final', or 'sealed' to the type.
24+
// class FinalWith with FinalClass {}
25+
// ^
26+
//
27+
import self as self;
28+
import "dart:core" as core;
29+
import "main_lib.dart" as mai;
30+
31+
import "org-dartlang-testcase:///main_lib.dart";
32+
33+
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
34+
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
35+
: super core::Object::•()
36+
;
37+
}
38+
class BaseWith extends self::_BaseWith&Object&BaseClass {
39+
synthetic constructor •() → self::BaseWith
40+
: super self::_BaseWith&Object&BaseClass::•()
41+
;
42+
}
43+
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
44+
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
45+
: super core::Object::•()
46+
;
47+
}
48+
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
49+
synthetic constructor •() → self::InterfaceWith
50+
: super self::_InterfaceWith&Object&InterfaceClass::•()
51+
;
52+
}
53+
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
54+
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
55+
: super core::Object::•()
56+
;
57+
}
58+
class FinalWith extends self::_FinalWith&Object&FinalClass {
59+
synthetic constructor •() → self::FinalWith
60+
: super self::_FinalWith&Object&FinalClass::•()
61+
;
62+
}
63+
64+
library /*isNonNullableByDefault*/;
65+
import self as mai;
66+
import "dart:core" as core;
67+
68+
base class BaseClass extends core::Object {
69+
synthetic constructor •() → mai::BaseClass
70+
: super core::Object::•()
71+
;
72+
}
73+
interface class InterfaceClass extends core::Object {
74+
synthetic constructor •() → mai::InterfaceClass
75+
: super core::Object::•()
76+
;
77+
}
78+
final class FinalClass extends core::Object {
79+
synthetic constructor •() → mai::FinalClass
80+
: super core::Object::•()
81+
;
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
6+
// class BaseWith with BaseClass {}
7+
// ^
8+
//
9+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
10+
// Try adding 'base', 'final', or 'sealed' to the type.
11+
// class BaseWith with BaseClass {}
12+
// ^
13+
//
14+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
15+
// class InterfaceWith with InterfaceClass {}
16+
// ^
17+
//
18+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
19+
// class FinalWith with FinalClass {}
20+
// ^
21+
//
22+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
23+
// Try adding 'base', 'final', or 'sealed' to the type.
24+
// class FinalWith with FinalClass {}
25+
// ^
26+
//
27+
import self as self;
28+
import "dart:core" as core;
29+
import "main_lib.dart" as mai;
30+
31+
import "org-dartlang-testcase:///main_lib.dart";
32+
33+
abstract final class _BaseWith&Object&BaseClass extends core::Object implements mai::BaseClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
34+
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
35+
: super core::Object::•()
36+
;
37+
}
38+
class BaseWith extends self::_BaseWith&Object&BaseClass {
39+
synthetic constructor •() → self::BaseWith
40+
: super self::_BaseWith&Object&BaseClass::•()
41+
;
42+
}
43+
abstract class _InterfaceWith&Object&InterfaceClass extends core::Object implements mai::InterfaceClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
44+
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
45+
: super core::Object::•()
46+
;
47+
}
48+
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
49+
synthetic constructor •() → self::InterfaceWith
50+
: super self::_InterfaceWith&Object&InterfaceClass::•()
51+
;
52+
}
53+
abstract final class _FinalWith&Object&FinalClass extends core::Object implements mai::FinalClass /*isAnonymousMixin,isEliminatedMixin,hasConstConstructor*/ {
54+
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
55+
: super core::Object::•()
56+
;
57+
}
58+
class FinalWith extends self::_FinalWith&Object&FinalClass {
59+
synthetic constructor •() → self::FinalWith
60+
: super self::_FinalWith&Object&FinalClass::•()
61+
;
62+
}
63+
64+
library /*isNonNullableByDefault*/;
65+
import self as mai;
66+
import "dart:core" as core;
67+
68+
base class BaseClass extends core::Object {
69+
synthetic constructor •() → mai::BaseClass
70+
: super core::Object::•()
71+
;
72+
}
73+
interface class InterfaceClass extends core::Object {
74+
synthetic constructor •() → mai::InterfaceClass
75+
: super core::Object::•()
76+
;
77+
}
78+
final class FinalClass extends core::Object {
79+
synthetic constructor •() → mai::FinalClass
80+
: super core::Object::•()
81+
;
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'main_lib.dart';
2+
3+
class BaseWith with BaseClass {}
4+
5+
class InterfaceWith with InterfaceClass {}
6+
7+
class FinalWith with FinalClass {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'main_lib.dart';
2+
3+
class BaseWith with BaseClass {}
4+
5+
class FinalWith with FinalClass {}
6+
7+
class InterfaceWith with InterfaceClass {}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
6+
// class BaseWith with BaseClass {}
7+
// ^
8+
//
9+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
10+
// Try adding 'base', 'final', or 'sealed' to the type.
11+
// class BaseWith with BaseClass {}
12+
// ^
13+
//
14+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
15+
// class InterfaceWith with InterfaceClass {}
16+
// ^
17+
//
18+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
19+
// class FinalWith with FinalClass {}
20+
// ^
21+
//
22+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
23+
// Try adding 'base', 'final', or 'sealed' to the type.
24+
// class FinalWith with FinalClass {}
25+
// ^
26+
//
27+
import self as self;
28+
import "dart:core" as core;
29+
import "main_lib.dart" as mai;
30+
31+
import "org-dartlang-testcase:///main_lib.dart";
32+
33+
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
34+
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
35+
: super core::Object::•()
36+
;
37+
}
38+
class BaseWith extends self::_BaseWith&Object&BaseClass {
39+
synthetic constructor •() → self::BaseWith
40+
: super self::_BaseWith&Object&BaseClass::•()
41+
;
42+
}
43+
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
44+
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
45+
: super core::Object::•()
46+
;
47+
}
48+
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
49+
synthetic constructor •() → self::InterfaceWith
50+
: super self::_InterfaceWith&Object&InterfaceClass::•()
51+
;
52+
}
53+
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
54+
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
55+
: super core::Object::•()
56+
;
57+
}
58+
class FinalWith extends self::_FinalWith&Object&FinalClass {
59+
synthetic constructor •() → self::FinalWith
60+
: super self::_FinalWith&Object&FinalClass::•()
61+
;
62+
}
63+
64+
library /*isNonNullableByDefault*/;
65+
import self as mai;
66+
import "dart:core" as core;
67+
68+
base class BaseClass extends core::Object {
69+
synthetic constructor •() → mai::BaseClass
70+
: super core::Object::•()
71+
;
72+
}
73+
interface class InterfaceClass extends core::Object {
74+
synthetic constructor •() → mai::InterfaceClass
75+
: super core::Object::•()
76+
;
77+
}
78+
final class FinalClass extends core::Object {
79+
synthetic constructor •() → mai::FinalClass
80+
: super core::Object::•()
81+
;
82+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:21: Error: The class 'BaseClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
6+
// class BaseWith with BaseClass {}
7+
// ^
8+
//
9+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:7:7: Error: The type 'BaseWith' must be 'base', 'final' or 'sealed' because the supertype 'BaseClass' is 'base'.
10+
// Try adding 'base', 'final', or 'sealed' to the type.
11+
// class BaseWith with BaseClass {}
12+
// ^
13+
//
14+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:9:26: Error: The class 'InterfaceClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
15+
// class InterfaceWith with InterfaceClass {}
16+
// ^
17+
//
18+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:22: Error: The class 'FinalClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
19+
// class FinalWith with FinalClass {}
20+
// ^
21+
//
22+
// pkg/front_end/testcases/class_modifiers/mixin/outside_library_modifier/main.dart:11:7: Error: The type 'FinalWith' must be 'base', 'final' or 'sealed' because the supertype 'FinalClass' is 'final'.
23+
// Try adding 'base', 'final', or 'sealed' to the type.
24+
// class FinalWith with FinalClass {}
25+
// ^
26+
//
27+
import self as self;
28+
import "dart:core" as core;
29+
import "main_lib.dart" as mai;
30+
31+
import "org-dartlang-testcase:///main_lib.dart";
32+
33+
abstract final class _BaseWith&Object&BaseClass = core::Object with mai::BaseClass /*isAnonymousMixin,hasConstConstructor*/ {
34+
const synthetic constructor •() → self::_BaseWith&Object&BaseClass
35+
: super core::Object::•()
36+
;
37+
}
38+
class BaseWith extends self::_BaseWith&Object&BaseClass {
39+
synthetic constructor •() → self::BaseWith
40+
: super self::_BaseWith&Object&BaseClass::•()
41+
;
42+
}
43+
abstract class _InterfaceWith&Object&InterfaceClass = core::Object with mai::InterfaceClass /*isAnonymousMixin,hasConstConstructor*/ {
44+
const synthetic constructor •() → self::_InterfaceWith&Object&InterfaceClass
45+
: super core::Object::•()
46+
;
47+
}
48+
class InterfaceWith extends self::_InterfaceWith&Object&InterfaceClass {
49+
synthetic constructor •() → self::InterfaceWith
50+
: super self::_InterfaceWith&Object&InterfaceClass::•()
51+
;
52+
}
53+
abstract final class _FinalWith&Object&FinalClass = core::Object with mai::FinalClass /*isAnonymousMixin,hasConstConstructor*/ {
54+
const synthetic constructor •() → self::_FinalWith&Object&FinalClass
55+
: super core::Object::•()
56+
;
57+
}
58+
class FinalWith extends self::_FinalWith&Object&FinalClass {
59+
synthetic constructor •() → self::FinalWith
60+
: super self::_FinalWith&Object&FinalClass::•()
61+
;
62+
}

0 commit comments

Comments
 (0)