[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 https://github.com/dart-lang/sdk/issues/60597


Change-Id: I34ca924be7f65021963c00f8eb9b9fda33164573
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436380
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Moritz Sümmermann <mosum@google.com>
This commit is contained in:
Moritz
2025-06-23 09:53:03 -07:00
committed by Commit Queue
parent bc9344870f
commit b112bb95cf
4 changed files with 26 additions and 3 deletions
+4
View File
@@ -1,3 +1,7 @@
## 0.4.1
- Fix bug in signature parsing.
## 0.4.0
- Update SDK constraint to `^3.5.0`.
+6 -1
View File
@@ -9,6 +9,10 @@ import 'constant.dart';
import 'helper.dart'; // Assuming helper.dart contains the deepEquals function
/// Represents the signature of a Dart method, categorizing its parameters.
///
/// This is a stop-gap due to https://github.com/dart-lang/sdk/issues/60597,
/// and this code should be removed once that bug is fixed.
// TODO(mosum): Delete this code
class Signature {
/// List of required positional parameter names.
final List<String> positionalParameters;
@@ -41,7 +45,8 @@ class Signature {
...namedParameters,
...namedOptionalParameters,
];
if (call.positionalArguments.length != names.length) {
if (call.positionalArguments.length + call.namedArguments.length !=
names.length) {
throw FormatException(
'''
Invalid number of arguments - $names vs ${call.positionalArguments} and ${call.namedArguments}''',
+1 -1
View File
@@ -1,7 +1,7 @@
name: record_use
description: >
The serialization logic and API for the usage recording SDK feature.
version: 0.4.0
version: 0.4.1
repository: https://github.com/dart-lang/sdk/tree/main/pkg/record_use
environment:
+15 -1
View File
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:record_use/src/signature.dart';
import 'package:record_use/record_use_internal.dart';
import 'package:test/test.dart';
void main() {
@@ -92,6 +92,20 @@ Future<void> fetchData(String url, int retries, [bool? cache, Duration? timeout]
expect(Signature.parseMethodSignature(signature), expected);
});
test('mixed parameters', () {
final signature = 'void config(String apiKey, {required String apiUrl})';
final parsed = Signature.parseMethodSignature(signature).parseArguments(
const CallWithArguments(
positionalArguments: [StringConstant('value')],
namedArguments: {'apiUrl': StringConstant('value2')},
loadingUnit: null,
location: Location(uri: ''),
),
);
expect(parsed.named.entries.single.value?.toValue(), 'value2');
expect(parsed.positional.single?.toValue(), 'value');
});
test('handles signatures with no parameters', () {
final signature = 'void doSomething()';
final expected = const Signature(