Skip to content

Commit 8b0e7a8

Browse files
authored
add test for enum assignability (#639)
Related to #638
1 parent 92ac810 commit 8b0e7a8

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

source_gen/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.2.8-dev
2+
13
## 1.2.7
24

35
* Update the value of the pubspec `repository` field.

source_gen/lib/src/type_checker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class UnresolvedAnnotationException implements Exception {
332332
// Trying to get more information on https://github.com/dart-lang/sdk/issues/45127
333333
log.warning(
334334
'''
335-
An unexpected error was thrown trying to get location information on `$annotatedElement` (${annotatedElement.runtimeType}).
335+
An unexpected error was thrown trying to get location information on `$annotatedElement` (${annotatedElement.runtimeType}).
336336
337337
Please file an issue at https://github.com/dart-lang/source_gen/issues/new
338338
Include the contents of this warning and the stack trace along with

source_gen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_gen
2-
version: 1.2.7
2+
version: 1.2.8-dev
33
description: >-
44
Source code generation builders and utilities for the Dart build system
55
repository: https://github.com/dart-lang/source_gen/tree/master/source_gen

source_gen/test/type_checker_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void main() {
2222
late InterfaceType staticUnmodifiableListView;
2323
late InterfaceType staticEnum;
2424
late TypeChecker staticIterableChecker;
25+
late TypeChecker staticEnumMixinChecker;
2526
late TypeChecker staticMapChecker;
2627
late TypeChecker staticMapMixinChecker;
2728
late TypeChecker staticHashMapChecker;
@@ -34,8 +35,10 @@ void main() {
3435
late TypeChecker staticGeneratorForAnnotationChecker;
3536

3637
// Resolved top-level types from this file
38+
late InterfaceType staticEnumMixin;
3739
late InterfaceType staticMapMixin;
3840
late InterfaceType staticMyEnum;
41+
late InterfaceType staticMyEnumWithMixin;
3942

4043
setUpAll(() async {
4144
late LibraryElement core;
@@ -82,6 +85,13 @@ void main() {
8285
nullabilitySuffix: NullabilitySuffix.none,
8386
);
8487
staticEnumChecker = TypeChecker.fromStatic(staticEnum);
88+
staticEnumMixin =
89+
(testSource.exportNamespace.get('MyEnumMixin')! as InterfaceElement)
90+
.instantiate(
91+
typeArguments: [],
92+
nullabilitySuffix: NullabilitySuffix.none,
93+
);
94+
staticEnumMixinChecker = TypeChecker.fromStatic(staticEnumMixin);
8595
staticMapMixin =
8696
(testSource.exportNamespace.get('MyMapMixin')! as InterfaceElement)
8797
.instantiate(
@@ -95,6 +105,12 @@ void main() {
95105
typeArguments: [],
96106
nullabilitySuffix: NullabilitySuffix.none,
97107
);
108+
staticMyEnumWithMixin =
109+
(testSource.exportNamespace.get('MyEnumWithMixin')! as InterfaceElement)
110+
.instantiate(
111+
typeArguments: [],
112+
nullabilitySuffix: NullabilitySuffix.none,
113+
);
98114

99115
staticHashMap = collection.getClass('HashMap')!.instantiate(
100116
typeArguments: [
@@ -130,6 +146,7 @@ void main() {
130146
required TypeChecker Function() checkEnum,
131147
required TypeChecker Function() checkMap,
132148
required TypeChecker Function() checkMapMixin,
149+
required TypeChecker Function() checkEnumMixin,
133150
required TypeChecker Function() checkHashMap,
134151
required TypeChecker Function() checkGenerator,
135152
required TypeChecker Function() checkGeneratorForAnnotation,
@@ -148,6 +165,19 @@ void main() {
148165
test('should be supertype of enum classes', () {
149166
expect(checkEnum().isSuperTypeOf(staticMyEnum), isTrue);
150167
});
168+
169+
test(
170+
'with mixins should be assignable to mixin class',
171+
() {
172+
expect(
173+
checkEnumMixin().isAssignableFromType(staticMyEnumWithMixin),
174+
isTrue,
175+
);
176+
},
177+
onPlatform: const {
178+
'windows': Skip('https://github.com/dart-lang/source_gen/issues/573'),
179+
},
180+
);
151181
});
152182

153183
group(
@@ -267,6 +297,7 @@ void main() {
267297
commonTests(
268298
checkIterable: () => const TypeChecker.fromRuntime(Iterable),
269299
checkEnum: () => const TypeChecker.fromRuntime(Enum),
300+
checkEnumMixin: () => const TypeChecker.fromRuntime(MyEnumMixin),
270301
checkMap: () => const TypeChecker.fromRuntime(Map),
271302
checkMapMixin: () => const TypeChecker.fromRuntime(MyMapMixin),
272303
checkHashMap: () => const TypeChecker.fromRuntime(HashMap),
@@ -280,6 +311,7 @@ void main() {
280311
commonTests(
281312
checkIterable: () => staticIterableChecker,
282313
checkEnum: () => staticEnumChecker,
314+
checkEnumMixin: () => staticEnumMixinChecker,
283315
checkMap: () => staticMapChecker,
284316
checkMapMixin: () => staticMapMixinChecker,
285317
checkHashMap: () => staticHashMapChecker,
@@ -292,6 +324,9 @@ void main() {
292324
commonTests(
293325
checkIterable: () => const TypeChecker.fromUrl('dart:core#Iterable'),
294326
checkEnum: () => const TypeChecker.fromUrl('dart:core#Enum'),
327+
checkEnumMixin: () => const TypeChecker.fromUrl(
328+
'asset:source_gen/test/type_checker_test.dart#MyEnumMixin',
329+
),
295330
checkMap: () => const TypeChecker.fromUrl('dart:core#Map'),
296331
checkMapMixin: () => const TypeChecker.fromUrl(
297332
'asset:source_gen/test/type_checker_test.dart#MyMapMixin',
@@ -560,3 +595,9 @@ final throwsUnresolvedAnnotationException = throwsA(
560595
mixin MyMapMixin on Map<dynamic, dynamic> {}
561596

562597
enum MyEnum { foo, bar }
598+
599+
mixin MyEnumMixin on Enum {
600+
int get value => 1;
601+
}
602+
603+
enum MyEnumWithMixin with MyEnumMixin { foo, bar }

0 commit comments

Comments
 (0)