Skip to content

Commit b112bb9

Browse files
mosuemCommit Queue
authored andcommitted
[record_use] Fix signature parsing bug
Another sign that we should switch to not having to use signature parsing anymore... Which needs Dart2Js to support named arguments. See also #60597 Change-Id: I34ca924be7f65021963c00f8eb9b9fda33164573 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436380 Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Moritz Sümmermann <[email protected]>
1 parent bc93448 commit b112bb9

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

pkg/record_use/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.1
2+
3+
- Fix bug in signature parsing.
4+
15
## 0.4.0
26

37
- Update SDK constraint to `^3.5.0`.

pkg/record_use/lib/src/signature.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import 'constant.dart';
99
import 'helper.dart'; // Assuming helper.dart contains the deepEquals function
1010

1111
/// Represents the signature of a Dart method, categorizing its parameters.
12+
///
13+
/// This is a stop-gap due to https://github.com/dart-lang/sdk/issues/60597,
14+
/// and this code should be removed once that bug is fixed.
15+
// TODO(mosum): Delete this code
1216
class Signature {
1317
/// List of required positional parameter names.
1418
final List<String> positionalParameters;
@@ -41,7 +45,8 @@ class Signature {
4145
...namedParameters,
4246
...namedOptionalParameters,
4347
];
44-
if (call.positionalArguments.length != names.length) {
48+
if (call.positionalArguments.length + call.namedArguments.length !=
49+
names.length) {
4550
throw FormatException(
4651
'''
4752
Invalid number of arguments - $names vs ${call.positionalArguments} and ${call.namedArguments}''',

pkg/record_use/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: record_use
22
description: >
33
The serialization logic and API for the usage recording SDK feature.
4-
version: 0.4.0
4+
version: 0.4.1
55
repository: https://github.com/dart-lang/sdk/tree/main/pkg/record_use
66

77
environment:

pkg/record_use/test/signature_test.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:record_use/src/signature.dart';
5+
import 'package:record_use/record_use_internal.dart';
66
import 'package:test/test.dart';
77

88
void main() {
@@ -92,6 +92,20 @@ Future<void> fetchData(String url, int retries, [bool? cache, Duration? timeout]
9292
expect(Signature.parseMethodSignature(signature), expected);
9393
});
9494

95+
test('mixed parameters', () {
96+
final signature = 'void config(String apiKey, {required String apiUrl})';
97+
final parsed = Signature.parseMethodSignature(signature).parseArguments(
98+
const CallWithArguments(
99+
positionalArguments: [StringConstant('value')],
100+
namedArguments: {'apiUrl': StringConstant('value2')},
101+
loadingUnit: null,
102+
location: Location(uri: ''),
103+
),
104+
);
105+
expect(parsed.named.entries.single.value?.toValue(), 'value2');
106+
expect(parsed.positional.single?.toValue(), 'value');
107+
});
108+
95109
test('handles signatures with no parameters', () {
96110
final signature = 'void doSomething()';
97111
final expected = const Signature(

0 commit comments

Comments
 (0)