mirror of
https://github.com/flutter/packages.git
synced 2025-06-27 21:28:33 +08:00
[pigeon] Made using enums in type arguments an error, added workaround (#527)
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
## NEXT
|
## 1.0.11
|
||||||
|
|
||||||
* [ci] Started transitioning to a Dart test runner, added windows support.
|
* [ci] Starts transition to a Dart test runner, adds windows support.
|
||||||
|
* [front-end] Starts issuing an error if enums are used in type arguments.
|
||||||
|
* [front-end] Passes through all enums, referenced or not so they can be used as
|
||||||
|
a work around for direct enum support.
|
||||||
|
|
||||||
## 1.0.10
|
## 1.0.10
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||||
const String pigeonVersion = '1.0.10';
|
const String pigeonVersion = '1.0.11';
|
||||||
|
|
||||||
/// Read all the content from [stdin] to a String.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
|
@ -423,6 +423,13 @@ List<Error> _validateAst(Root root, String source) {
|
|||||||
lineNumber: _calculateLineNumberNullable(source, field.offset),
|
lineNumber: _calculateLineNumberNullable(source, field.offset),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if (customEnums.contains(typeArgument.baseName)) {
|
||||||
|
result.add(Error(
|
||||||
|
message:
|
||||||
|
'Enum types aren\'t supported in type arguments in "${field.name}" in class "${klass.name}".',
|
||||||
|
lineNumber: _calculateLineNumberNullable(source, field.offset),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(validTypes.contains(field.type.baseName) ||
|
if (!(validTypes.contains(field.type.baseName) ||
|
||||||
@ -544,9 +551,6 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor<Object?> {
|
|||||||
.removeWhere((Class x) => !referencedTypeNames.contains(x.name));
|
.removeWhere((Class x) => !referencedTypeNames.contains(x.name));
|
||||||
|
|
||||||
final List<Enum> referencedEnums = List<Enum>.from(_enums);
|
final List<Enum> referencedEnums = List<Enum>.from(_enums);
|
||||||
referencedEnums.removeWhere(
|
|
||||||
(final Enum anEnum) => !referencedTypeNames.contains(anEnum.name));
|
|
||||||
|
|
||||||
final Root completeRoot =
|
final Root completeRoot =
|
||||||
Root(apis: _apis, classes: referencedClasses, enums: referencedEnums);
|
Root(apis: _apis, classes: referencedClasses, enums: referencedEnums);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ name: pigeon
|
|||||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||||
repository: https://github.com/flutter/packages/tree/master/packages/pigeon
|
repository: https://github.com/flutter/packages/tree/master/packages/pigeon
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||||
version: 1.0.10 # This must match the version in lib/generator_tools.dart
|
version: 1.0.11 # This must match the version in lib/generator_tools.dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
@ -901,4 +901,49 @@ abstract class Api {
|
|||||||
final ParseResults results = _parseSource(code);
|
final ParseResults results = _parseSource(code);
|
||||||
expect(results.errors.length, 0);
|
expect(results.errors.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Enum key not supported', () {
|
||||||
|
const String code = '''
|
||||||
|
enum MessageKey {
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
description,
|
||||||
|
}
|
||||||
|
|
||||||
|
class Message {
|
||||||
|
int? id;
|
||||||
|
Map<MessageKey?, String?>? additionalProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostApi()
|
||||||
|
abstract class HostApiBridge {
|
||||||
|
void sendMessage(Message message);
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
final ParseResults results = _parseSource(code);
|
||||||
|
expect(results.errors.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Export unreferenced enums', () {
|
||||||
|
const String code = '''
|
||||||
|
enum MessageKey {
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
description,
|
||||||
|
}
|
||||||
|
|
||||||
|
class Message {
|
||||||
|
int? id;
|
||||||
|
Map<int?, String?>? additionalProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostApi()
|
||||||
|
abstract class HostApiBridge {
|
||||||
|
void sendMessage(Message message);
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
final ParseResults results = _parseSource(code);
|
||||||
|
expect(results.root.enums.length, 1);
|
||||||
|
expect(results.root.enums[0].name, 'MessageKey');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user