Skip to content

Commit 02b9c2c

Browse files
[pigeon] Fixes error from constructor parameter sharing name with attached field for a ProxyApi (#10541)
Attached parameters aren't passed in constructor message call so they can share name with constructor parameter. ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 1905069 commit 02b9c2c

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 26.1.3
22

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

56
## 26.1.2

packages/pigeon/lib/src/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'generator.dart';
1515
/// The current version of pigeon.
1616
///
1717
/// This must match the version in pubspec.yaml.
18-
const String pigeonVersion = '26.1.2';
18+
const String pigeonVersion = '26.1.3';
1919

2020
/// Read all the content from [stdin] to a String.
2121
String readStdin() {

packages/pigeon/lib/src/pigeon_lib_internal.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,10 @@ List<Error> _validateProxyApi(
10791079
result.add(unsupportedDataClassError(parameter));
10801080
}
10811081

1082-
if (api.fields.any((ApiField field) => field.name == parameter.name) ||
1082+
if (api.fields.any(
1083+
(ApiField field) =>
1084+
field.name == parameter.name && !field.isAttached,
1085+
) ||
10831086
api.flutterMethods.any(
10841087
(Method method) => method.name == parameter.name,
10851088
)) {

packages/pigeon/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
5-
version: 26.1.2 # This must match the version in lib/src/generator_tools.dart
5+
version: 26.1.3 # This must match the version in lib/src/generator_tools.dart
66

77
environment:
88
sdk: ^3.9.0

packages/pigeon/test/pigeon_lib_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,39 @@ abstract class MyClass {
17571757
),
17581758
);
17591759
});
1760+
1761+
test('constructor parameters can share name of attached fields', () {
1762+
const code = '''
1763+
@ProxyApi()
1764+
abstract class MyClass {
1765+
MyClass(int aField);
1766+
1767+
@attached
1768+
late MyClass aField;
1769+
}
1770+
''';
1771+
final ParseResults parseResult = parseSource(code);
1772+
expect(parseResult.errors, isEmpty);
1773+
});
1774+
1775+
test('constructor parameters can not share name of unattached fields', () {
1776+
const code = '''
1777+
@ProxyApi()
1778+
abstract class MyClass {
1779+
MyClass(int aField);
1780+
1781+
late MyClass? aField;
1782+
}
1783+
''';
1784+
final ParseResults parseResult = parseSource(code);
1785+
expect(parseResult.errors, isNotEmpty);
1786+
expect(
1787+
parseResult.errors[0].message,
1788+
contains(
1789+
'Parameter names must not share a name with a field or callback method in constructor "" in API: "MyClass"',
1790+
),
1791+
);
1792+
});
17601793
});
17611794

17621795
group('event channel validation', () {

0 commit comments

Comments
 (0)