Skip to content
Merged
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
# Disabled until custom_lint is removed
# - packages/freezed_lint
channel:
- stable
# - stable
- master
Comment thread
rrousselGit marked this conversation as resolved.
dependencies:
- get
- downgrade
Expand Down Expand Up @@ -54,7 +55,7 @@ jobs:

- name: Check format
# Check dart format only on stable
if: matrix.channel == 'stable'
if: matrix.channel == 'master'
run: dart format --set-exit-if-changed .
working-directory: ${{ matrix.package }}

Expand All @@ -71,7 +72,7 @@ jobs:

- name: Run tests
run: |
if grep -q "name: example" "pubspec.yaml"; then
if grep -q "name: freezed_example" "pubspec.yaml"; then
flutter test
else
dart test
Expand Down
4 changes: 4 additions & 0 deletions packages/freezed/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased 3.2.6-dev.1

Support analyzer 12.0

## 3.2.5 - 2026-02-03

Support analyzer 10.0
Expand Down
2 changes: 2 additions & 0 deletions packages/freezed/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dev_dependencies:
build_runner:
flutter_test:
sdk: flutter
# To support "downgrade" checks due to a transitive dependency not handling it correctly
file: '>=7.0.0'

dependency_overrides:
freezed:
Expand Down
6 changes: 3 additions & 3 deletions packages/freezed/example/test/diagnosticable_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:example/diagnosticable.dart' as diagnosticable;
import 'package:example/non_diagnosticable.dart' as non_diagnosticable;
import 'package:example/time_slot.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:freezed_example/diagnosticable.dart' as diagnosticable;
import 'package:freezed_example/non_diagnosticable.dart' as non_diagnosticable;
import 'package:freezed_example/time_slot.dart';

void main() {
test('overriding toString works', () {
Expand Down
2 changes: 1 addition & 1 deletion packages/freezed/example/test/json_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:example/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:freezed_example/main.dart';

void main() {
test('Union toJson', () {
Expand Down
36 changes: 24 additions & 12 deletions packages/freezed/lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ When specifying fields in non-factory constructor then specifying factory constr

_assertValidFreezedConstructorUsage(
constructor,
className: declaration.name.lexeme,
className: declaration.namePart.typeName.lexeme,
);

final excludedProperties =
Expand All @@ -299,7 +299,7 @@ When specifying fields in non-factory constructor then specifying factory constr
final isEjected = unitsExcludingGeneratedFiles.any(
(e) => e.declarations
.whereType<ClassDeclaration>()
.map((e) => e.name.lexeme)
.map((e) => e.namePart.typeName.lexeme)
.contains(redirectedName),
);

Expand Down Expand Up @@ -522,7 +522,7 @@ class CopyWithTarget {

extension on NamedType {
bool isSuperMixin(ClassDeclaration declaration) =>
name.lexeme == '_\$${declaration.name.lexeme.public}';
name.lexeme == '_\$${declaration.namePart.typeName.lexeme.public}';
}

class Class {
Expand Down Expand Up @@ -582,7 +582,7 @@ class Class {
false;
if (!has$ClassMixin) {
throw InvalidGenerationSourceError(
'Classes using @freezed must use `with _\$${declaration.name.lexeme.public}`.',
'Classes using @freezed must use `with _\$${declaration.namePart.typeName.lexeme.public}`.',
element: declaration.declaredFragment?.element,
node: declaration,
);
Expand Down Expand Up @@ -624,7 +624,7 @@ class Class {
if (cloneableProperty == null) {
throw InvalidGenerationSourceError(
'''
The class ${declaration.name.lexeme} requested a copyWith implementation, yet the parameter `${param.name}` is not cloneable.
The class ${declaration.namePart.typeName.lexeme} requested a copyWith implementation, yet the parameter `${param.name}` is not cloneable.

To fix, either:
- Disable copyWith using @Freezed(copyWith: false)
Expand Down Expand Up @@ -669,7 +669,7 @@ To fix, either:

return Class(
node: declaration,
name: declaration.name.lexeme,
name: declaration.namePart.typeName.lexeme,
copyWithTarget: copyWithInvocation,
properties: properties,
superCall: superCall,
Expand Down Expand Up @@ -1076,7 +1076,7 @@ To fix, either:
if (!shouldUseExtends &&
field.getter != null &&
!field.getter!.isAbstract &&
!field.getter!.isSynthetic) {
field.getter!.nonSynthetic != field.getter) {
throw InvalidGenerationSourceError(
'Getters require a MyClass._() constructor',
element: field,
Expand Down Expand Up @@ -1332,14 +1332,26 @@ extension ClassDeclarationX on ClassDeclaration {
}

Iterable<ConstructorDeclaration> get constructors {
return members.whereType<ConstructorDeclaration>();
final that = body;
switch (that) {
case BlockClassBody():
return that.members.whereType<ConstructorDeclaration>();
default:
return const [];
}
}

Iterable<(FieldDeclaration, VariableDeclaration)> get properties {
return members
.whereType<FieldDeclaration>()
.where((e) => !e.isStatic)
.expand((e) => e.fields.variables.map((f) => (e, f)));
final that = body;
switch (that) {
case BlockClassBody():
return that.members
.whereType<FieldDeclaration>()
.where((e) => !e.isStatic)
.expand((e) => e.fields.variables.map((f) => (e, f)));
default:
return const [];
}
}
Comment thread
rrousselGit marked this conversation as resolved.

bool needsJsonSerializable(Library library) {
Expand Down
5 changes: 4 additions & 1 deletion packages/freezed/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
sdk: ">=3.8.0 <4.0.0"

dependencies:
analyzer: '>=9.0.0 <11.0.0'
analyzer: '>=12.0.0 <13.0.0'
build: ">=3.0.0 <5.0.0"
build_config: ^1.1.0
collection: ^1.15.0
Expand All @@ -31,3 +31,6 @@ dev_dependencies:
expect_error: ^1.0.10
flutter:
sdk: flutter

# To support "downgrade" checks due to a transitive dependency not handling it correctly
file: '>=7.0.0'
1 change: 1 addition & 0 deletions packages/freezed/test/integration/decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract class Decorator with _$Decorator {
}

class _WeirdDecorator {
// ignore: unused_element_parameter, false positive https://github.com/dart-lang/sdk/issues/63229
const _WeirdDecorator(this.a, {this.b});

final String a;
Expand Down
2 changes: 1 addition & 1 deletion packages/freezed/test/json_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'integration/json.dart';

Future<void> main() async {
final jsonFile = await resolveSources(
readAllSourcesFromFilesystem: true,
readAllSourcesFromFilesystem: true,
{'freezed|test/integration/json.dart': useAssetReader},
(r) => r.libraries.firstWhere(
(element) => element.firstFragment.source.toString().contains('json'),
Expand Down
Loading