Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.0.2

* Prevents optional and non-positional parameters in flutterApis.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Flutter APIs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't get changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change must have gotten lost when I merged branches, I definitely changed it.


## 15.0.1

* [java] Adds @CanIgnoreReturnValue annotation to class builder.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '15.0.1';
const String pigeonVersion = '15.0.2';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
15 changes: 15 additions & 0 deletions packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,21 @@ List<Error> _validateAst(Root root, String source) {
lineNumber: _calculateLineNumberNullable(source, param.offset),
));
}
if (api.location == ApiLocation.flutter) {
if (!param.isPositional) {
result.add(Error(
message:
'FlutterApi method parameters must be positional, in method "${method.name}" in API: "${api.name}"',
lineNumber: _calculateLineNumberNullable(source, param.offset),
));
} else if (param.isOptional) {
result.add(Error(
message:
'FlutterApi method parameters must not be optional, in method "${method.name}" in API: "${api.name}"',
lineNumber: _calculateLineNumberNullable(source, param.offset),
));
}
}
}
if (method.objcSelector.isNotEmpty) {
if (':'.allMatches(method.objcSelector).length !=
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pigeon
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
version: 15.0.1 # This must match the version in lib/generator_tools.dart
version: 15.0.2 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
28 changes: 28 additions & 0 deletions packages/pigeon/test/pigeon_lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1324,4 +1324,32 @@ abstract class Api {
});
await completer.future;
});

test('unsupported non-positional parameters on FlutterApi', () {
const String code = '''
@FlutterApi()
abstract class Api {
int? calc({int? anInt});
}
''';

final ParseResults results = parseSource(code);
expect(results.errors.length, 1);
expect(results.errors[0].message,
contains('FlutterApi method parameters must be positional'));
});

test('unsupported optional parameters on FlutterApi', () {
const String code = '''
@FlutterApi()
abstract class Api {
int? calc([int? anInt]);
}
''';

final ParseResults results = parseSource(code);
expect(results.errors.length, 1);
expect(results.errors[0].message,
contains('FlutterApi method parameters must not be optional'));
});
}