mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 01:33:59 +08:00
[pigeon] added an error until we support primitive enums (#423)
This commit is contained in:
@ -380,7 +380,7 @@ List<Error> _validateAst(Root root, String source) {
|
||||
final List<Error> result = <Error>[];
|
||||
final List<String> customClasses =
|
||||
root.classes.map((Class x) => x.name).toList();
|
||||
final List<String> customEnums = root.enums.map((Enum x) => x.name).toList();
|
||||
final Iterable<String> customEnums = root.enums.map((Enum x) => x.name);
|
||||
for (final Class klass in root.classes) {
|
||||
for (final Field field in klass.fields) {
|
||||
if (field.typeArguments != null) {
|
||||
@ -416,6 +416,20 @@ List<Error> _validateAst(Root root, String source) {
|
||||
lineNumber: _calculateLineNumberNullable(source, method.offset),
|
||||
));
|
||||
}
|
||||
if (customEnums.contains(method.argType)) {
|
||||
result.add(Error(
|
||||
message:
|
||||
'Enums aren\'t yet supported for primitive arguments: "${method.argType}" in API: "${api.name}" method: "${method.name}" (https://github.com/flutter/flutter/issues/87307)',
|
||||
lineNumber: _calculateLineNumberNullable(source, method.offset),
|
||||
));
|
||||
}
|
||||
if (customEnums.contains(method.returnType)) {
|
||||
result.add(Error(
|
||||
message:
|
||||
'Enums aren\'t yet supported for primitive return types: "${method.returnType}" in API: "${api.name}" method: "${method.name}" (https://github.com/flutter/flutter/issues/87307)',
|
||||
lineNumber: _calculateLineNumberNullable(source, method.offset),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,4 +576,42 @@ abstract class WithStaticFieldApi {
|
||||
expect(parseResult.errors[0].message, contains('static field'));
|
||||
expect(parseResult.errors[0].lineNumber, isNotNull);
|
||||
});
|
||||
|
||||
test('enums argument', () {
|
||||
// TODO(gaaclarke): Make this not an error: https://github.com/flutter/flutter/issues/87307
|
||||
const String code = '''
|
||||
|
||||
enum Foo {
|
||||
one,
|
||||
two,
|
||||
}
|
||||
|
||||
@HostApi()
|
||||
abstract class Api {
|
||||
void doit(Foo foo);
|
||||
}
|
||||
''';
|
||||
final ParseResults parseResult = _parseSource(code);
|
||||
expect(parseResult.errors.length, equals(1));
|
||||
expect(parseResult.errors[0].message, contains('Enums'));
|
||||
});
|
||||
|
||||
test('enums return value', () {
|
||||
// TODO(gaaclarke): Make this not an error: https://github.com/flutter/flutter/issues/87307
|
||||
const String code = '''
|
||||
|
||||
enum Foo {
|
||||
one,
|
||||
two,
|
||||
}
|
||||
|
||||
@HostApi()
|
||||
abstract class Api {
|
||||
Foo doit();
|
||||
}
|
||||
''';
|
||||
final ParseResults parseResult = _parseSource(code);
|
||||
expect(parseResult.errors.length, equals(1));
|
||||
expect(parseResult.errors[0].message, contains('Enums'));
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user