fix(dart): fix dart library warnings (#3691)
## Why?
## What does this PR do?
## Related issues
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
diff --git a/ci/build_linux_wheels.py b/ci/build_linux_wheels.py
index 532d091..041636a 100755
--- a/ci/build_linux_wheels.py
+++ b/ci/build_linux_wheels.py
@@ -42,11 +42,11 @@
CONTAINER_SCRIPT_PATH = "ci/tasks/python_container_build_script.sh"
DEFAULT_X86_IMAGES = [
- "quay.io/pypa/manylinux2014_x86_64@sha256:a6ccaa6194d55e9e8564ba7b70f396934e72e383c241ef711358e2ef96e9e635",
+ "quay.io/pypa/manylinux2014_x86_64@sha256:735bc0817ff4a2390ead63c67ba34b36037d0a8ffd64791e3599ed4802df43d9",
]
DEFAULT_AARCH64_IMAGES = [
- "quay.io/pypa/manylinux2014_aarch64@sha256:9ec54d4892c8f5cf6ce6888582adecb108a27147a4f0f02696cfbb4baa8ab496",
+ "quay.io/pypa/manylinux2014_aarch64@sha256:e29044ae873f56799ea849c794a163246ac78120d7a6b458a17f918c05a143e1",
]
ARCH_ALIASES = {
diff --git a/dart/packages/fory-test/pubspec.yaml b/dart/packages/fory-test/pubspec.yaml
index fd6b896..5dd9c8a 100644
--- a/dart/packages/fory-test/pubspec.yaml
+++ b/dart/packages/fory-test/pubspec.yaml
@@ -22,12 +22,12 @@
resolution: workspace
environment:
- sdk: ^3.6.1
+ sdk: ^3.7.0
dependencies:
fory: 0.18.0-dev
dev_dependencies:
- build_runner: ^2.4.13
- lints: ^5.0.0
- test: ^1.24.0
+ build_runner: '>=2.7.0 <3.0.0'
+ lints: ^6.1.0
+ test: ^1.31.1
diff --git a/dart/packages/fory/analysis_options.yaml b/dart/packages/fory/analysis_options.yaml
index 354c0be..231f9de 100644
--- a/dart/packages/fory/analysis_options.yaml
+++ b/dart/packages/fory/analysis_options.yaml
@@ -21,5 +21,7 @@
exclude:
- .dart_tool/**
- example/**/*.fory.dart
+ - test/**/*.fory.dart
errors:
+ deprecated_member_use: ignore
unintended_html_in_doc_comment: ignore
diff --git a/dart/packages/fory/lib/src/codegen/fory_generator.dart b/dart/packages/fory/lib/src/codegen/fory_generator.dart
index f6036c0..d2ab00d 100644
--- a/dart/packages/fory/lib/src/codegen/fory_generator.dart
+++ b/dart/packages/fory/lib/src/codegen/fory_generator.dart
@@ -48,29 +48,37 @@
}
final class ForyGenerator extends Generator {
- static final TypeChecker _foryStructChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _foryStructChecker = TypeChecker.typeNamed(
ForyStruct,
+ inPackage: 'fory',
);
- static final TypeChecker _foryFieldChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _foryFieldChecker = TypeChecker.typeNamed(
ForyField,
+ inPackage: 'fory',
);
- static final TypeChecker _listFieldChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _listFieldChecker = TypeChecker.typeNamed(
ListField,
+ inPackage: 'fory',
);
- static final TypeChecker _arrayFieldChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _arrayFieldChecker = TypeChecker.typeNamed(
ArrayField,
+ inPackage: 'fory',
);
- static final TypeChecker _setFieldChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _setFieldChecker = TypeChecker.typeNamed(
SetField,
+ inPackage: 'fory',
);
- static final TypeChecker _mapFieldChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _mapFieldChecker = TypeChecker.typeNamed(
MapField,
+ inPackage: 'fory',
);
- static final TypeChecker _typeSpecChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _typeSpecChecker = TypeChecker.typeNamed(
TypeSpec,
+ inPackage: 'fory',
);
- static final TypeChecker _foryUnionChecker = TypeChecker.fromRuntime(
+ static const TypeChecker _foryUnionChecker = TypeChecker.typeNamed(
ForyUnion,
+ inPackage: 'fory',
);
final Map<String, String> _importPrefixByLibraryIdentifier =
@@ -93,8 +101,9 @@
final generatedApiName = '${helperBaseName}Fory';
final enumSpecs = enumElements.map(_analyzeEnum).toList(growable: false);
- final structSpecs =
- annotatedClasses.map(_analyzeStruct).toList(growable: false);
+ final structSpecs = annotatedClasses
+ .map(_analyzeStruct)
+ .toList(growable: false);
final output = StringBuffer()
..writeln(
'// ignore_for_file: implementation_imports, invalid_use_of_internal_member, no_leading_underscores_for_local_identifiers, unreachable_switch_case, unused_element, unused_element_parameter, unnecessary_null_comparison',
@@ -142,8 +151,7 @@
void _buildImportPrefixMap(LibraryReader library) {
_importPrefixByLibraryIdentifier.clear();
- for (final import
- in library.element.definingCompilationUnit.libraryImports) {
+ for (final import in library.element.firstFragment.libraryImports) {
final importedLibrary = import.importedLibrary;
final prefix = import.prefix?.element.displayName;
if (importedLibrary == null || prefix == null || prefix.isEmpty) {
@@ -166,8 +174,9 @@
final idValue = reader?.peek('id');
final nullableValue = reader?.peek('nullable');
final dynamicValue = reader?.peek('dynamic');
- final rawFieldId =
- idValue == null || idValue.isNull ? null : idValue.intValue;
+ final rawFieldId = idValue == null || idValue.isNull
+ ? null
+ : idValue.intValue;
if (rawFieldId != null && rawFieldId < 0) {
throw InvalidGenerationSourceError(
'Fory field id must be non-negative.',
@@ -188,8 +197,9 @@
name: field.displayName,
type: field.type,
displayType: _typeCodeString(field.type),
- identifier:
- fieldId != null ? '$fieldId' : _toSnakeCase(field.displayName),
+ identifier: fieldId != null
+ ? '$fieldId'
+ : _toSnakeCase(field.displayName),
id: fieldId,
nullable: nullable,
ref: ref,
@@ -264,9 +274,7 @@
if (_isList(type) &&
typeSpec?.typeId != null &&
_isDenseArrayTypeId(typeSpec!.typeId!)) {
- return _fieldTypeForArrayListCarrier(
- errorElement,
- );
+ return _fieldTypeForArrayListCarrier(errorElement);
}
if (typeSpec?.typeId != null && typeSpec!.typeId != expectedTypeId) {
throw InvalidGenerationSourceError(
@@ -334,13 +342,7 @@
);
}
final typeId = typeSpec?.typeId ?? _typeIdFor(type);
- _validateScalarTypeOverride(
- type,
- typeId,
- dynamic,
- typeSpec,
- errorElement,
- );
+ _validateScalarTypeOverride(type, typeId, dynamic, typeSpec, errorElement);
return _GeneratedFieldTypeSpec(
typeLiteral: _typeReferenceLiteral(type),
declaredTypeName: _typeReferenceLiteral(type),
@@ -357,9 +359,10 @@
List<_GeneratedFieldSpec> fields,
) {
final unnamedConstructor = element.unnamedConstructor;
- final hasZeroArgConstructor = unnamedConstructor != null &&
+ final hasZeroArgConstructor =
+ unnamedConstructor != null &&
!unnamedConstructor.isFactory &&
- unnamedConstructor.parameters.every(
+ unnamedConstructor.formalParameters.every(
(parameter) => parameter.isOptional,
);
if (hasZeroArgConstructor && fields.every((field) => field.writable)) {
@@ -379,7 +382,7 @@
};
final arguments = <_ConstructorArgumentSpec>[];
final constructorFieldNames = <String>{};
- for (final parameter in unnamedConstructor.parameters) {
+ for (final parameter in unnamedConstructor.formalParameters) {
final parameterName = parameter.displayName;
final field = fieldByName[parameterName];
if (field == null) {
@@ -1039,8 +1042,9 @@
nullable: fieldType.nullable,
ref: fieldType.ref,
dynamic: fieldType.dynamic,
- arguments:
- fieldType.arguments.map(_fromDebugFieldType).toList(growable: false),
+ arguments: fieldType.arguments
+ .map(_fromDebugFieldType)
+ .toList(growable: false),
);
}
@@ -1373,9 +1377,7 @@
);
if (fieldBytes == null) {
if (start != null) {
- runs.add(
- _DirectGeneratedPrimitiveRun(start, index - 1, bytes),
- );
+ runs.add(_DirectGeneratedPrimitiveRun(start, index - 1, bytes));
start = null;
bytes = 0;
}
@@ -1385,9 +1387,7 @@
bytes += fieldBytes;
}
if (start != null) {
- runs.add(
- _DirectGeneratedPrimitiveRun(start, fields.length - 1, bytes),
- );
+ runs.add(_DirectGeneratedPrimitiveRun(start, fields.length - 1, bytes));
}
return runs;
}
@@ -1469,8 +1469,9 @@
output.writeln('${indent}final bytes${run.start} = bufferBytes(buffer);');
}
if (_directGeneratedRunUsesView(fields, run)) {
- output
- .writeln('${indent}final view${run.start} = bufferByteData(buffer);');
+ output.writeln(
+ '${indent}final view${run.start} = bufferByteData(buffer);',
+ );
}
}
@@ -1487,8 +1488,9 @@
output.writeln('${indent}final bytes${run.start} = bufferBytes(buffer);');
}
if (_directGeneratedRunUsesView(fields, run)) {
- output
- .writeln('${indent}final view${run.start} = bufferByteData(buffer);');
+ output.writeln(
+ '${indent}final view${run.start} = bufferByteData(buffer);',
+ );
}
}
@@ -1696,14 +1698,24 @@
case TypeIds.varInt32:
final result = 'result$fieldIndex';
_writeDirectGeneratedVarUint32Read(
- output, result, bytes, offset, indent);
+ output,
+ result,
+ bytes,
+ offset,
+ indent,
+ );
output.writeln(
'$indent$target = (($result >>> 1) ^ -($result & 1)).toSigned(32);',
);
case TypeIds.varUint32:
final result = 'result$fieldIndex';
_writeDirectGeneratedVarUint32Read(
- output, result, bytes, offset, indent);
+ output,
+ result,
+ bytes,
+ offset,
+ indent,
+ );
output.writeln('$indent$target = $result;');
default:
throw StateError(
@@ -1966,7 +1978,9 @@
return 'generatedCheckedUint64Int($valueExpression)';
default:
return _checkedGeneratedScalarExpression(
- field.fieldType.typeId, valueExpression);
+ field.fieldType.typeId,
+ valueExpression,
+ );
}
}
if (field.type.isDartCoreDouble ||
@@ -1992,8 +2006,7 @@
String _generatedFieldInfoWriteValueExpression(
_GeneratedFieldSpec field,
String valueExpression,
- ) =>
- valueExpression;
+ ) => valueExpression;
String _nullExpression(
DartType type, {
@@ -2152,7 +2165,8 @@
if (leftCompressed != rightCompressed) {
return leftCompressed ? 1 : -1;
}
- final sizeCompare = _primitiveSize(right.fieldType.typeId) -
+ final sizeCompare =
+ _primitiveSize(right.fieldType.typeId) -
_primitiveSize(left.fieldType.typeId);
if (sizeCompare != 0) {
return sizeCompare;
@@ -2300,7 +2314,7 @@
}
DartObject? _fieldAnnotationOf(FieldElement field) {
- for (final metadata in field.metadata) {
+ for (final metadata in field.metadata.annotations) {
final annotation = metadata.computeConstantValue();
final annotationType = annotation?.type;
if (annotationType != null &&
@@ -2357,9 +2371,7 @@
if (annotationType != null &&
_arrayFieldChecker.isExactlyType(annotationType)) {
final element = _readRequiredTypeSpec(reader.peek('element'), field);
- return _TypeSpecInfo(
- typeId: _arrayTypeIdForElementSpec(element, field),
- );
+ return _TypeSpecInfo(typeId: _arrayTypeIdForElementSpec(element, field));
}
if (annotationType != null &&
_setFieldChecker.isExactlyType(annotationType)) {
@@ -2404,11 +2416,7 @@
final dynamic = _readBoolOverride(reader.peek('dynamic'));
switch (typeName) {
case 'DeclaredType':
- return _TypeSpecInfo(
- nullable: nullable,
- ref: ref,
- dynamic: dynamic,
- );
+ return _TypeSpecInfo(nullable: nullable, ref: ref, dynamic: dynamic);
case 'ListType':
return _TypeSpecInfo(
typeId: TypeIds.list,
@@ -2637,9 +2645,9 @@
'varint' => varint,
'tagged' when tagged != null => tagged,
_ => throw InvalidGenerationSourceError(
- 'Unsupported encoding $encodingValue for type spec.',
- element: field,
- ),
+ 'Unsupported encoding $encodingValue for type spec.',
+ element: field,
+ ),
};
}
@@ -2714,9 +2722,9 @@
TypeIds.float32 => TypeIds.float32Array,
TypeIds.float64 => TypeIds.float64Array,
_ => throw InvalidGenerationSourceError(
- 'ArrayType requires a numeric or bool scalar element type without fixed/tagged encoding.',
- element: field,
- ),
+ 'ArrayType requires a numeric or bool scalar element type without fixed/tagged encoding.',
+ element: field,
+ ),
};
}
@@ -2754,10 +2762,11 @@
final valid = switch (_typeLiteral(nonNullable)) {
'bool' => typeId == TypeIds.boolType,
'int' => _isSupportedIntTypeId(typeId),
- 'double' => typeId == TypeIds.float16 ||
- typeId == TypeIds.bfloat16 ||
- typeId == TypeIds.float32 ||
- typeId == TypeIds.float64,
+ 'double' =>
+ typeId == TypeIds.float16 ||
+ typeId == TypeIds.bfloat16 ||
+ typeId == TypeIds.float32 ||
+ typeId == TypeIds.float64,
'String' => typeId == TypeIds.string,
'Int64' => _isSigned64TypeId(typeId),
'Uint64' => _isUnsigned64TypeId(typeId),
@@ -3021,8 +3030,8 @@
final method = element.getMethod('fromRawValue');
if (method == null ||
!method.isStatic ||
- method.parameters.length != 1 ||
- !method.parameters.single.type.isDartCoreInt) {
+ method.formalParameters.length != 1 ||
+ !method.formalParameters.single.type.isDartCoreInt) {
return false;
}
return method.returnType.element == element;
@@ -3133,8 +3142,9 @@
if (nonNullable.typeArguments.isEmpty) {
return baseName;
}
- final typeArguments =
- nonNullable.typeArguments.map(_typeCodeString).join(', ');
+ final typeArguments = nonNullable.typeArguments
+ .map(_typeCodeString)
+ .join(', ');
return '$baseName<$typeArguments>';
}
return nonNullable.getDisplayString();
@@ -3202,9 +3212,7 @@
return false;
}
- bool _fieldTypeUsesNestedTypeDefinitions(
- _GeneratedFieldTypeSpec fieldType,
- ) {
+ bool _fieldTypeUsesNestedTypeDefinitions(_GeneratedFieldTypeSpec fieldType) {
if (fieldType.dynamic == true || TypeIds.isUserType(fieldType.typeId)) {
return true;
}
@@ -3306,9 +3314,9 @@
final List<String> postConstructionFieldNames;
const _ConstructorPlan.mutable()
- : mode = _ConstructorMode.mutable,
- arguments = const <_ConstructorArgumentSpec>[],
- postConstructionFieldNames = const <String>[];
+ : mode = _ConstructorMode.mutable,
+ arguments = const <_ConstructorArgumentSpec>[],
+ postConstructionFieldNames = const <String>[];
const _ConstructorPlan.constructor({
required this.arguments,
diff --git a/dart/packages/fory/pubspec.yaml b/dart/packages/fory/pubspec.yaml
index 801474c..4e1d88d 100644
--- a/dart/packages/fory/pubspec.yaml
+++ b/dart/packages/fory/pubspec.yaml
@@ -25,16 +25,16 @@
resolution: workspace
environment:
- sdk: ^3.6.1
+ sdk: ^3.7.0
dependencies:
- analyzer: '>=6.5.0 <8.0.0'
- build: ^2.4.1
- build_config: ^1.1.0
- meta: ^1.14.0
- source_gen: ^2.0.0
+ analyzer: '>=8.0.0 <14.0.0'
+ build: '>=3.0.0 <5.0.0'
+ build_config: '>=1.2.0 <1.4.0'
+ meta: '>=1.14.0 <2.0.0'
+ source_gen: '>=3.0.0 <5.0.0'
dev_dependencies:
- build_runner: ^2.4.13
- lints: ^5.0.0
- test: ^1.24.0
+ build_runner: '>=2.7.0 <3.0.0'
+ lints: ^6.1.0
+ test: ^1.31.1
diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml
index d8edf3f..8ab2d9d 100644
--- a/dart/pubspec.yaml
+++ b/dart/pubspec.yaml
@@ -16,20 +16,20 @@
# under the License.
name: fory_dart
-description: apache fory dart support
+description: Apache Fory Dart workspace for the runtime package, generated serializers, and integration tests.
version: 0.18.0-dev
# repository: https://github.com/my_org/my_repo
environment:
- sdk: ^3.6.1
+ sdk: ^3.7.0
# Add regular dependencies here.
dependencies:
fory: 0.18.0-dev
- build_runner: ^2.4.13
+ build_runner: '>=2.7.0 <3.0.0'
dev_dependencies:
- lints: ^5.0.0
- test: ^1.24.0
+ lints: ^6.1.0
+ test: ^1.31.1
workspace:
- packages/fory
- packages/fory-test