Skip to content

Commit 7311952

Browse files
committed
refactor(dart): remove dead record companion path
1 parent 72d4b22 commit 7311952

2 files changed

Lines changed: 11 additions & 34 deletions

File tree

dart/packages/fory/lib/src/codegen/fory_generator.dart

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,14 @@ final class ForyGenerator extends Generator {
14261426
element: boundary,
14271427
);
14281428
}
1429+
if (type is RecordType || type.isDartCoreRecord) {
1430+
throw InvalidGenerationSourceError(
1431+
'Private-field companion for ${boundary.displayName} cannot expose '
1432+
'record type ${type.getDisplayString()} because ordinary ForyStruct '
1433+
'fields do not support record types.',
1434+
element: boundary,
1435+
);
1436+
}
14291437
final nullable =
14301438
type.nullabilitySuffix == NullabilitySuffix.question ? '?' : '';
14311439
final alias = type.alias;
@@ -1483,33 +1491,6 @@ final class ForyGenerator extends Generator {
14831491
}
14841492
return '${type.element.displayName}$nullable';
14851493
}
1486-
if (type is RecordType) {
1487-
final positional = <String>[];
1488-
for (final field in type.positionalFields) {
1489-
positional.add(
1490-
_companionTypeCode(
1491-
field.type,
1492-
boundary,
1493-
allowedTypeParameters: allowedTypeParameters,
1494-
requireNamespace: requireNamespace,
1495-
useAlias: useAlias,
1496-
),
1497-
);
1498-
}
1499-
final named = <String>[];
1500-
for (final field in type.namedFields) {
1501-
named.add(
1502-
'${_companionTypeCode(field.type, boundary, allowedTypeParameters: allowedTypeParameters, requireNamespace: requireNamespace, useAlias: useAlias)} '
1503-
'${field.name}',
1504-
);
1505-
}
1506-
final components = <String>[
1507-
...positional,
1508-
if (named.isNotEmpty) '{${named.join(', ')}}',
1509-
];
1510-
final trailingComma = positional.length == 1 && named.isEmpty ? ',' : '';
1511-
return '(${components.join(', ')}$trailingComma)$nullable';
1512-
}
15131494
throw InvalidGenerationSourceError(
15141495
'Private-field companion for ${boundary.displayName} cannot render '
15151496
'${type.getDisplayString()} as an exact public Dart type.',

dart/packages/fory/test/struct_private_companion_generator_test.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,21 +865,17 @@ abstract class Boundary {
865865
expect(output, isNot(contains('static _Count ')));
866866
});
867867

868-
test('renders a single-positional record signature exactly', () async {
868+
test('rejects record signatures unsupported by ordinary structs', () async {
869869
const inputPath = 'test/record_signature.dart';
870-
final output = await _generate(
870+
await _expectGenerationError(
871871
inputPath: inputPath,
872872
source: _librarySource(inputPath, '''
873873
@ForyStruct(exposePrivateFields: true)
874874
abstract class Boundary {
875875
(int,) _value = (0,);
876876
}
877877
'''),
878-
);
879-
880-
expect(
881-
output,
882-
matches(RegExp(r'static \(int,\) \$g[0-9a-f]{16}\(Boundary value\)')),
878+
message: 'ordinary ForyStruct fields do not support record types',
883879
);
884880
});
885881

0 commit comments

Comments
 (0)