Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 26.1.3

* [dart] Fixes error from constructor parameter sharing name with attached field for a ProxyApi.
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

## 26.1.2
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/src/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'generator.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '26.1.2';
const String pigeonVersion = '26.1.3';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
5 changes: 4 additions & 1 deletion packages/pigeon/lib/src/pigeon_lib_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,10 @@ List<Error> _validateProxyApi(
result.add(unsupportedDataClassError(parameter));
}

if (api.fields.any((ApiField field) => field.name == parameter.name) ||
if (api.fields.any(
(ApiField field) =>
field.name == parameter.name && !field.isAttached,
) ||
api.flutterMethods.any(
(Method method) => method.name == parameter.name,
)) {
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: 26.1.2 # This must match the version in lib/src/generator_tools.dart
version: 26.1.3 # This must match the version in lib/src/generator_tools.dart

environment:
sdk: ^3.9.0
Expand Down
33 changes: 33 additions & 0 deletions packages/pigeon/test/pigeon_lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,39 @@ abstract class MyClass {
),
);
});

test('constructor parameters can share name of attached fields', () {
const code = '''
@ProxyApi()
abstract class MyClass {
MyClass(int aField);

@attached
late MyClass aField;
}
''';
final ParseResults parseResult = parseSource(code);
expect(parseResult.errors, isEmpty);
});

test('constructor parameters can not share name of unattached fields', () {
const code = '''
@ProxyApi()
abstract class MyClass {
MyClass(int aField);

late MyClass? aField;
}
''';
final ParseResults parseResult = parseSource(code);
expect(parseResult.errors, isNotEmpty);
expect(
parseResult.errors[0].message,
contains(
'Parameter names must not share a name with a field or callback method in constructor "" in API: "MyClass"',
),
);
});
});

group('event channel validation', () {
Expand Down