Skip to content

Commit 43cff26

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Add supertype to enum classes.
TEST= language/enum/enum_test Change-Id: I83b7fd1c29103c3aa4dc7ad3e41141fb8c62339e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203564 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 253764e commit 43cff26

File tree

78 files changed

+233
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+233
-90
lines changed

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
### `dart:html`
66

7-
* [#44319][]: `convertNativeToDart_Dictionary()` now converts objects
8-
recursively, this fixes APIs like MediaStreamTrack.getCapabilities
9-
that convert between Maps and browser Dictionaries.
7+
* [#44319][]: `convertNativeToDart_Dictionary()` now converts objects
8+
recursively, this fixes APIs like MediaStreamTrack.getCapabilities
9+
that convert between Maps and browser Dictionaries.
1010

1111
[44319]: (https://github.com/dart-lang/sdk/issues/44319)
1212

@@ -23,6 +23,8 @@
2323

2424
#### `dart:core`
2525

26+
* Introduce `Enum` interface implemented by all `enum` declarations.
27+
2628
* The native `DateTime` class now better handles local time around
2729
daylight saving changes that are not precisely one hour.
2830
(No change on the Web which uses the JavaScript `Date` object.)

pkg/_fe_analyzer_shared/test/inheritance/data/object_opt_in/core.dart

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Object {
2424
String toString() => '';
2525
}
2626

27+
/*class: Enum:Enum,Object*/
28+
abstract class Enum {}
29+
2730
/*class: Null:Null,Object*/
2831
class Null {
2932
factory Null._uninstantiable() {

pkg/_fe_analyzer_shared/test/inheritance/data/object_opt_out/core.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Object {
2626
String toString() => '';
2727
}
2828

29+
/*class: Enum:Enum,Object*/
30+
abstract class Enum {}
31+
2932
/*class: Null:Null,Object*/
3033
class Null {
3134
factory Null._uninstantiable() {

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

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class double {}
3838
class int {}
3939
class num {}
4040
class Object {}
41+
class Enum {}
4142
class Iterable<E> {}
4243
class Map<K, V> {}
4344
class Null {}

pkg/analyzer/lib/dart/element/type_provider.dart

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ abstract class TypeProvider {
3131
/// Return the type representing the built-in type `dynamic`.
3232
DartType get dynamicType;
3333

34+
/// Return the element representing the built-in type `Enum`.
35+
ClassElement get enumElement;
36+
37+
/// Return the type representing the built-in type `Enum`.
38+
InterfaceType get enumType;
39+
3440
/// Return the type representing the built-in type `Function`.
3541
InterfaceType get functionType;
3642

pkg/analyzer/lib/src/dart/element/element.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,8 @@ class EnumElementImpl extends AbstractClassElementImpl {
26682668
}
26692669

26702670
@override
2671-
List<InterfaceType> get allSupertypes => <InterfaceType>[supertype];
2671+
List<InterfaceType> get allSupertypes =>
2672+
<InterfaceType>[...interfaces, supertype];
26722673

26732674
List<FieldElement> get constants {
26742675
return fields.where((field) => !field.isSynthetic).toList();
@@ -2700,7 +2701,8 @@ class EnumElementImpl extends AbstractClassElementImpl {
27002701
bool get hasStaticMember => true;
27012702

27022703
@override
2703-
List<InterfaceType> get interfaces => const <InterfaceType>[];
2704+
List<InterfaceType> get interfaces =>
2705+
<InterfaceType>[library.typeProvider.enumType];
27042706

27052707
@override
27062708
bool get isAbstract => false;

pkg/analyzer/lib/src/dart/element/type_provider.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Set<String> _nonSubtypableDartAsyncClassNames = {
2727
const Set<String> _nonSubtypableDartCoreClassNames = {
2828
'bool',
2929
'double',
30+
'Enum',
3031
'int',
3132
'Null',
3233
'num',
@@ -104,6 +105,7 @@ class TypeProviderImpl extends TypeProviderBase {
104105

105106
ClassElement? _boolElement;
106107
ClassElement? _doubleElement;
108+
ClassElement? _enumElement;
107109
ClassElement? _futureElement;
108110
ClassElement? _futureOrElement;
109111
ClassElement? _intElement;
@@ -122,6 +124,7 @@ class TypeProviderImpl extends TypeProviderBase {
122124
InterfaceType? _deprecatedType;
123125
InterfaceType? _doubleType;
124126
InterfaceType? _doubleTypeQuestion;
127+
InterfaceType? _enumType;
125128
InterfaceType? _functionType;
126129
InterfaceType? _futureDynamicType;
127130
InterfaceType? _futureNullType;
@@ -151,7 +154,7 @@ class TypeProviderImpl extends TypeProviderBase {
151154
required LibraryElement coreLibrary,
152155
required LibraryElement asyncLibrary,
153156
required bool isNonNullableByDefault,
154-
}) : _coreLibrary = coreLibrary,
157+
}) : _coreLibrary = coreLibrary,
155158
_asyncLibrary = asyncLibrary,
156159
isNonNullableByDefault = isNonNullableByDefault;
157160

@@ -219,6 +222,16 @@ class TypeProviderImpl extends TypeProviderBase {
219222
@override
220223
DartType get dynamicType => DynamicTypeImpl.instance;
221224

225+
@override
226+
ClassElement get enumElement {
227+
return _enumElement ??= _getClassElement(_coreLibrary, "Enum");
228+
}
229+
230+
@override
231+
InterfaceType get enumType {
232+
return _enumType ??= _getType(_coreLibrary, "Enum");
233+
}
234+
222235
@override
223236
InterfaceType get functionType {
224237
return _functionType ??= _getType(_coreLibrary, "Function");

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

+4
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ class Object {
523523
external dynamic noSuchMethod(Invocation invocation);
524524
}
525525
526+
abstract class Enum {
527+
int get index;
528+
}
529+
526530
abstract class Pattern {
527531
Iterable<Match> allMatches(String string, [int start = 0]);
528532
}

pkg/analyzer/test/src/dart/resolution/enum_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var v = [E1.a, E2.b];
2424
''');
2525

2626
var v = findElement.topVar('v');
27-
assertType(v.type, 'List<Object>');
27+
assertType(v.type, 'List<Enum>');
2828
}
2929

3030
test_isConstantEvaluated() async {

pkg/analyzer/test/src/summary/resynthesize_common.dart

+50
Original file line numberDiff line numberDiff line change
@@ -4624,6 +4624,8 @@ library
46244624
enum E @5
46254625
codeOffset: 0
46264626
codeLength: 26
4627+
interfaces
4628+
Enum
46274629
fields
46284630
synthetic final index @-1
46294631
type: int
@@ -9667,6 +9669,8 @@ library
96679669
synthetic @-1
96689670
enums
96699671
enum E @30
9672+
interfaces
9673+
Enum
96709674
fields
96719675
synthetic final index @-1
96729676
type: int
@@ -11764,6 +11768,8 @@ library
1176411768
definingUnit
1176511769
enums
1176611770
enum E @5
11771+
interfaces
11772+
Enum
1176711773
fields
1176811774
synthetic final index @-1
1176911775
type: int
@@ -11816,6 +11822,8 @@ library
1181611822
definingUnit
1181711823
enums
1181811824
enum E @5
11825+
interfaces
11826+
Enum
1181911827
fields
1182011828
synthetic final index @-1
1182111829
type: int
@@ -14445,6 +14453,8 @@ library
1444514453
definingUnit
1444614454
enums
1444714455
enum E @5
14456+
interfaces
14457+
Enum
1444814458
fields
1444914459
synthetic final index @-1
1445014460
type: int
@@ -14467,6 +14477,8 @@ library
1446714477
synthetic toString @-1
1446814478
returnType: String
1446914479
enum E @19
14480+
interfaces
14481+
Enum
1447014482
fields
1447114483
synthetic final index @-1
1447214484
type: int
@@ -14723,6 +14735,8 @@ library
1472314735
enums
1472414736
enum E @65
1472514737
documentationComment: /**\n * Docs\n */
14738+
interfaces
14739+
Enum
1472614740
fields
1472714741
synthetic final index @-1
1472814742
type: int
@@ -14758,6 +14772,8 @@ library
1475814772
definingUnit
1475914773
enums
1476014774
enum E @5
14775+
interfaces
14776+
Enum
1476114777
fields
1476214778
synthetic final index @-1
1476314779
type: int
@@ -14804,6 +14820,8 @@ library
1480414820
definingUnit
1480514821
enums
1480614822
enum E @5
14823+
interfaces
14824+
Enum
1480714825
fields
1480814826
synthetic final index @-1
1480914827
type: int
@@ -14863,6 +14881,8 @@ library
1486314881
definingUnit
1486414882
enums
1486514883
enum E @5
14884+
interfaces
14885+
Enum
1486614886
fields
1486714887
synthetic final index @-1
1486814888
type: int
@@ -14894,6 +14914,8 @@ library
1489414914
definingUnit
1489514915
enums
1489614916
enum E1 @5
14917+
interfaces
14918+
Enum
1489714919
fields
1489814920
synthetic final index @-1
1489914921
type: int
@@ -14912,6 +14934,8 @@ library
1491214934
synthetic toString @-1
1491314935
returnType: String
1491414936
enum E2 @20
14937+
interfaces
14938+
Enum
1491514939
fields
1491614940
synthetic final index @-1
1491714941
type: int
@@ -14997,6 +15021,8 @@ library
1499715021
superKeyword: super @0
1499815022
enums
1499915023
enum E @5
15024+
interfaces
15025+
Enum
1500015026
fields
1500115027
synthetic final index @-1
1500215028
type: int
@@ -22565,6 +22591,8 @@ library
2256522591
definingUnit
2256622592
enums
2256722593
enum E @19
22594+
interfaces
22595+
Enum
2256822596
fields
2256922597
synthetic final index @-1
2257022598
type: int
@@ -22634,6 +22662,8 @@ library
2263422662
returnType: dynamic
2263522663
enums
2263622664
enum E @64
22665+
interfaces
22666+
Enum
2263722667
fields
2263822668
synthetic final index @-1
2263922669
type: int
@@ -22707,6 +22737,8 @@ library
2270722737
staticElement: self::@getter::a
2270822738
staticType: null
2270922739
token: a @15
22740+
interfaces
22741+
Enum
2271022742
fields
2271122743
synthetic final index @-1
2271222744
type: int
@@ -24202,6 +24234,8 @@ library
2420224234
staticElement: self::@getter::foo
2420324235
staticType: null
2420424236
token: foo @17
24237+
interfaces
24238+
Enum
2420524239
fields
2420624240
synthetic final index @-1
2420724241
type: int
@@ -25392,6 +25426,8 @@ library
2539225426
synthetic @-1
2539325427
enums
2539425428
enum E @5
25429+
interfaces
25430+
Enum
2539525431
fields
2539625432
synthetic final index @-1
2539725433
type: int
@@ -26873,6 +26909,8 @@ library
2687326909
definingUnit
2687426910
enums
2687526911
enum E @5
26912+
interfaces
26913+
Enum
2687626914
fields
2687726915
synthetic final index @-1
2687826916
type: int
@@ -29182,6 +29220,8 @@ library
2918229220
synthetic @-1
2918329221
enums
2918429222
enum E @16
29223+
interfaces
29224+
Enum
2918529225
fields
2918629226
synthetic final index @-1
2918729227
type: int
@@ -29288,6 +29328,8 @@ library
2928829328
synthetic @-1
2928929329
enums
2929029330
enum E @27
29331+
interfaces
29332+
Enum
2929129333
fields
2929229334
synthetic final index @-1
2929329335
type: int
@@ -29328,6 +29370,8 @@ library
2932829370
synthetic @-1
2932929371
enums
2933029372
enum E @42
29373+
interfaces
29374+
Enum
2933129375
fields
2933229376
synthetic final index @-1
2933329377
type: int
@@ -29405,6 +29449,8 @@ library
2940529449
synthetic @-1
2940629450
enums
2940729451
enum E @27
29452+
interfaces
29453+
Enum
2940829454
fields
2940929455
synthetic final index @-1
2941029456
type: int
@@ -29480,6 +29526,8 @@ library
2948029526
synthetic @-1
2948129527
enums
2948229528
enum E @27
29529+
interfaces
29530+
Enum
2948329531
fields
2948429532
synthetic final index @-1
2948529533
type: int
@@ -29623,6 +29671,8 @@ library
2962329671
definingUnit
2962429672
enums
2962529673
enum E @5
29674+
interfaces
29675+
Enum
2962629676
fields
2962729677
synthetic final index @-1
2962829678
type: int

0 commit comments

Comments
 (0)