Skip to content

Commit babbb49

Browse files
committed
Merge branch 'master' of https://github.com/rrousselGit/freezed
2 parents 781d96a + afe5f7a commit babbb49

13 files changed

Lines changed: 714 additions & 51 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
# Disabled until custom_lint is removed
2323
# - packages/freezed_lint
2424
channel:
25-
- stable
25+
# - stable
26+
- master
2627
dependencies:
2728
- get
2829
- downgrade
@@ -54,7 +55,7 @@ jobs:
5455

5556
- name: Check format
5657
# Check dart format only on stable
57-
if: matrix.channel == 'stable'
58+
if: matrix.channel == 'master'
5859
run: dart format --set-exit-if-changed .
5960
working-directory: ${{ matrix.package }}
6061

@@ -71,7 +72,7 @@ jobs:
7172

7273
- name: Run tests
7374
run: |
74-
if grep -q "name: example" "pubspec.yaml"; then
75+
if grep -q "name: freezed_example" "pubspec.yaml"; then
7576
flutter test
7677
else
7778
dart test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.iml
33
build/
44
node_modules
5-
/package-lock.json
5+
/package-lock.json
6+
.dart_tool

packages/freezed/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased 3.2.6-dev.1
2+
3+
Support analyzer 12.0
4+
15
## 3.2.5 - 2026-02-03
26

37
Support analyzer 10.0

packages/freezed/example/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ dev_dependencies:
1919
build_runner:
2020
flutter_test:
2121
sdk: flutter
22+
# To support "downgrade" checks due to a transitive dependency not handling it correctly
23+
file: ">=7.0.0"
2224

2325
dependency_overrides:
2426
freezed:

packages/freezed/lib/src/ast.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import 'package:analyzer/dart/ast/ast.dart';
2-
import 'package:analyzer/dart/ast/token.dart';
32
import 'package:analyzer/dart/element/element.dart';
43

54
extension AstX on AstNode {
65
String? get documentation {
7-
final builder = StringBuffer();
8-
9-
for (
10-
Token? token = beginToken.precedingComments;
11-
token != null;
12-
token = token.next
13-
) {
14-
builder.writeln(token);
15-
}
6+
final node = switch (this) {
7+
DefaultFormalParameter(:final parameter) => parameter,
8+
_ => this,
9+
};
1610

17-
if (builder.isEmpty) return null;
11+
if (node case AnnotatedNode(:final documentationComment?)) {
12+
return '${documentationComment.tokens.map((token) => token.lexeme).join('\n')}\n';
13+
}
1814

19-
return builder.toString();
15+
return null;
2016
}
2117
}
2218

packages/freezed/lib/src/models.dart

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ When specifying fields in non-factory constructor then specifying factory constr
278278

279279
_assertValidFreezedConstructorUsage(
280280
constructor,
281-
className: declaration.name.lexeme,
281+
className: declaration.namePart.typeName.lexeme,
282282
);
283283

284284
final excludedProperties =
@@ -299,7 +299,7 @@ When specifying fields in non-factory constructor then specifying factory constr
299299
final isEjected = unitsExcludingGeneratedFiles.any(
300300
(e) => e.declarations
301301
.whereType<ClassDeclaration>()
302-
.map((e) => e.name.lexeme)
302+
.map((e) => e.namePart.typeName.lexeme)
303303
.contains(redirectedName),
304304
);
305305

@@ -522,7 +522,7 @@ class CopyWithTarget {
522522

523523
extension on NamedType {
524524
bool isSuperMixin(ClassDeclaration declaration) =>
525-
name.lexeme == '_\$${declaration.name.lexeme.public}';
525+
name.lexeme == '_\$${declaration.namePart.typeName.lexeme.public}';
526526
}
527527

528528
class Class {
@@ -582,7 +582,7 @@ class Class {
582582
false;
583583
if (!has$ClassMixin) {
584584
throw InvalidGenerationSourceError(
585-
'Classes using @freezed must use `with _\$${declaration.name.lexeme.public}`.',
585+
'Classes using @freezed must use `with _\$${declaration.namePart.typeName.lexeme.public}`.',
586586
element: declaration.declaredFragment?.element,
587587
node: declaration,
588588
);
@@ -624,7 +624,7 @@ class Class {
624624
if (cloneableProperty == null) {
625625
throw InvalidGenerationSourceError(
626626
'''
627-
The class ${declaration.name.lexeme} requested a copyWith implementation, yet the parameter `${param.name}` is not cloneable.
627+
The class ${declaration.namePart.typeName.lexeme} requested a copyWith implementation, yet the parameter `${param.name}` is not cloneable.
628628
629629
To fix, either:
630630
- Disable copyWith using @Freezed(copyWith: false)
@@ -669,7 +669,7 @@ To fix, either:
669669

670670
return Class(
671671
node: declaration,
672-
name: declaration.name.lexeme,
672+
name: declaration.namePart.typeName.lexeme,
673673
copyWithTarget: copyWithInvocation,
674674
properties: properties,
675675
superCall: superCall,
@@ -1076,7 +1076,7 @@ To fix, either:
10761076
if (!shouldUseExtends &&
10771077
field.getter != null &&
10781078
!field.getter!.isAbstract &&
1079-
!field.getter!.isSynthetic) {
1079+
field.getter!.isOriginDeclaration) {
10801080
throw InvalidGenerationSourceError(
10811081
'Getters require a MyClass._() constructor',
10821082
element: field,
@@ -1332,14 +1332,26 @@ extension ClassDeclarationX on ClassDeclaration {
13321332
}
13331333

13341334
Iterable<ConstructorDeclaration> get constructors {
1335-
return members.whereType<ConstructorDeclaration>();
1335+
final that = body;
1336+
switch (that) {
1337+
case BlockClassBody():
1338+
return that.members.whereType<ConstructorDeclaration>();
1339+
default:
1340+
return const [];
1341+
}
13361342
}
13371343

13381344
Iterable<(FieldDeclaration, VariableDeclaration)> get properties {
1339-
return members
1340-
.whereType<FieldDeclaration>()
1341-
.where((e) => !e.isStatic)
1342-
.expand((e) => e.fields.variables.map((f) => (e, f)));
1345+
final that = body;
1346+
switch (that) {
1347+
case BlockClassBody():
1348+
return that.members
1349+
.whereType<FieldDeclaration>()
1350+
.where((e) => !e.isStatic)
1351+
.expand((e) => e.fields.variables.map((f) => (e, f)));
1352+
default:
1353+
return const [];
1354+
}
13431355
}
13441356

13451357
bool needsJsonSerializable(Library library) {

packages/freezed/pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
sdk: ">=3.8.0 <4.0.0"
1111

1212
dependencies:
13-
analyzer: '>=9.0.0 <11.0.0'
13+
analyzer: '>=12.0.0 <13.0.0'
1414
build: ">=3.0.0 <5.0.0"
1515
build_config: ^1.1.0
1616
collection: ^1.15.0
@@ -31,3 +31,6 @@ dev_dependencies:
3131
expect_error: ^1.0.10
3232
flutter:
3333
sdk: flutter
34+
35+
# To support "downgrade" checks due to a transitive dependency not handling it correctly
36+
file: '>=7.0.0'

packages/freezed/test/common_types_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void main() {
8383
nullabilityDifference: 42,
8484
typeDifference: 21,
8585
);
86-
// expect-error: UNDEFINED_GETTER
86+
// expect-error: undefined_getter
8787
value.unknown;
8888
}
8989
'''),
@@ -120,10 +120,10 @@ void main() {
120120
param.copyWith(
121121
// Since not all unions have a nullable property, we cannot assign "null"
122122
// on the shared interface.
123-
// expect-error: ARGUMENT_TYPE_NOT_ASSIGNABLE
123+
// expect-error: argument_type_not_assignable
124124
nullabilityDifference: null,
125125
// Since not all unions use the same type, we can't clone that property at all.
126-
// expect-error: UNDEFINED_NAMED_PARAMETER
126+
// expect-error: undefined_named_parameter
127127
typeDifference: 42,
128128
);
129129
}
@@ -174,10 +174,10 @@ void main() {
174174
param.copyWith.value(
175175
// Since not all unions have a nullable property, we cannot assign "null"
176176
// on the shared interface.
177-
// expect-error: ARGUMENT_TYPE_NOT_ASSIGNABLE
177+
// expect-error: argument_type_not_assignable
178178
nullabilityDifference: null,
179179
// Since not all unions use the same type, we can't clone that property at all.
180-
// expect-error: UNDEFINED_NAMED_PARAMETER
180+
// expect-error: undefined_named_parameter
181181
typeDifference: 42,
182182
);
183183
}
@@ -204,7 +204,7 @@ import 'integration/common_types.dart';
204204
205205
void main() {
206206
final param = CommonUnfreezed.one(a: 42, b: 3.14);
207-
// expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER
207+
// expect-error: assignment_to_final_no_setter
208208
param.a = 42.24;
209209
// OK since all union cases are typed the same
210210
param.b = 42;

packages/freezed/test/decorator_test.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,20 @@ void main() {
9797
errorResult.errors.map((e) => e.errorCode.name),
9898
anyOf([
9999
[
100-
'UNUSED_RESULT',
101-
'UNUSED_RESULT',
102-
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
103-
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
104-
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
105-
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
100+
'unused_result',
101+
'unused_result',
102+
'deprecated_member_use_from_same_package',
103+
'deprecated_member_use_from_same_package',
104+
'deprecated_member_use_from_same_package',
105+
'deprecated_member_use_from_same_package',
106106
],
107107
[
108-
'UNUSED_RESULT',
109-
'UNUSED_RESULT',
110-
'DEPRECATED_MEMBER_USE',
111-
'DEPRECATED_MEMBER_USE',
112-
'DEPRECATED_MEMBER_USE',
113-
'DEPRECATED_MEMBER_USE',
108+
'unused_result',
109+
'unused_result',
110+
'deprecated_member_use',
111+
'deprecated_member_use',
112+
'deprecated_member_use',
113+
'deprecated_member_use',
114114
],
115115
]),
116116
);

packages/freezed/test/deep_copy_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ void main() {
734734
as ErrorsResult;
735735

736736
expect(errorResult.errors.map((e) => e.errorCode.name), [
737-
'UNUSED_RESULT',
738-
'UNUSED_RESULT',
737+
'unused_result',
738+
'unused_result',
739739
]);
740740
});
741741
}

0 commit comments

Comments
 (0)