From 753c5a7d79cbe13478130d161d067b7b8a3eb665 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Mon, 15 Aug 2022 22:54:00 +0200 Subject: [PATCH 01/23] feat: add common properties with different nullability to base mixin --- .../freezed/lib/src/freezed_generator.dart | 41 ++++++++++++++---- .../lib/src/templates/concrete_template.dart | 1 + .../freezed/lib/src/templates/copy_with.dart | 40 ++++++++++-------- .../lib/src/templates/parameter_template.dart | 12 ++++++ .../freezed/lib/src/templates/properties.dart | 6 +++ .../freezed/lib/src/templates/prototypes.dart | 2 + packages/freezed/pubspec.yaml | 4 +- .../integration/multiple_constructors.dart | 8 ++++ .../test/multiple_constructors_test.dart | 42 ++++++++++++++++++- 9 files changed, 129 insertions(+), 27 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index d153adbc..af5245fe 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -147,6 +147,8 @@ class FreezedGenerator extends ParserGenerator { isPossiblyDartCollection: commonParameter.isPossiblyDartCollection, // TODO: support hasJsonKey hasJsonKey: false, + isCommonWithDifferentNullability: + commonParameter.isCommonWithDifferentNullability, ), ]; } @@ -252,27 +254,50 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C ) { return constructorsNeedsGeneration.first.parameters.allParameters .map((parameter) { - var hasAnyFinalProperty = false; + var anyMatchingPropertyIsFinal = false; + var anyMatchingPropertyIsNullable = false; + for (final constructor in constructorsNeedsGeneration) { final matchingParameter = constructor.parameters.allParameters.firstWhereOrNull((p) { - return p.name == parameter.name && p.type == parameter.type; + return p.name == parameter.name && + _typeStringWithoutNullability(p.type) == + _typeStringWithoutNullability(parameter.type); }); if (matchingParameter == null) return null; - if (matchingParameter.isFinal) hasAnyFinalProperty = true; + if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; + if (matchingParameter.isNullable) + anyMatchingPropertyIsNullable = true; } - if (hasAnyFinalProperty) { - return parameter.copyWith(isFinal: true); + final isNullable = + parameter.isNullable || anyMatchingPropertyIsNullable; + + if (parameter.isNullable != isNullable) { + print(parameter.name); } - return parameter; + return parameter.copyWith( + isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, + isNullable: isNullable, + type: isNullable && (parameter.type?.endsWith('?') == false) + ? '${parameter.type}?' + : parameter.type, + isCommonWithDifferentNullability: + parameter.isNullable != isNullable, + ); }) .whereNotNull() .toList(); } + String? _typeStringWithoutNullability(String? type) { + return type?.endsWith('?') == true + ? type?.substring(0, type.length - 1) + : type; + } + Future> _parseConstructorsNeedsGeneration( BuildStep buildStep, ClassElement element, @@ -606,7 +631,9 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C ).toList(), genericsDefinition: data.genericsDefinitionTemplate, genericsParameter: data.genericsParameterTemplate, - allProperties: commonProperties, + allProperties: commonProperties + .whereNot((element) => element.isCommonWithDifferentNullability) + .toList(), data: data, ); diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index 02091120..52099b90 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -135,6 +135,7 @@ ${copyWith?.abstractCopyWithGetter ?? ''} doc: '', isPossiblyDartCollection: false, showDefaultValue: false, + isCommonWithDifferentNullability: false, ); parameters = ParametersTemplate( diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index cae0b4a3..e7566f2c 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:freezed/src/templates/parameter_template.dart'; import 'package:freezed/src/templates/properties.dart'; @@ -65,23 +66,28 @@ ${_abstractDeepCopyMethods().join()} final body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: commonProperties.map((e) { - return Parameter( - decorators: e.decorators, - name: e.name, - isNullable: false, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - showDefaultValue: false, - isRequired: false, - defaultValueSource: '', - type: e.type, - doc: e.doc, - isPossiblyDartCollection: e.isPossiblyDartCollection, - ); - }).toList(), + namedParameters: commonProperties + .map((e) { + return Parameter( + decorators: e.decorators, + name: e.name, + isNullable: false, + isFinal: false, + isDartList: false, + isDartMap: false, + isDartSet: false, + showDefaultValue: false, + isRequired: false, + defaultValueSource: '', + type: e.type, + doc: e.doc, + isPossiblyDartCollection: e.isPossiblyDartCollection, + isCommonWithDifferentNullability: + e.isCommonWithDifferentNullability, + ); + }) + .whereNot((element) => element.isCommonWithDifferentNullability) + .toList(), ), returnType: '_value.copyWith', ); diff --git a/packages/freezed/lib/src/templates/parameter_template.dart b/packages/freezed/lib/src/templates/parameter_template.dart index b70ade6a..88d0d7e7 100644 --- a/packages/freezed/lib/src/templates/parameter_template.dart +++ b/packages/freezed/lib/src/templates/parameter_template.dart @@ -82,6 +82,7 @@ class ParametersTemplate { doc: await documentationOfParameter(e, buildStep), isPossiblyDartCollection: e.type.isPossiblyDartCollection, showDefaultValue: true, + isCommonWithDifferentNullability: false, ); if (isAssignedToThis) return LocalParameter.fromParameter(value); @@ -184,6 +185,7 @@ class Parameter { required this.isFinal, required this.isPossiblyDartCollection, required this.showDefaultValue, + required this.isCommonWithDifferentNullability, }); Parameter.fromParameter(Parameter p) @@ -201,6 +203,7 @@ class Parameter { showDefaultValue: p.showDefaultValue, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, + isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, ); final String? type; @@ -216,6 +219,7 @@ class Parameter { final bool isPossiblyDartCollection; final bool isFinal; final String doc; + final bool isCommonWithDifferentNullability; Parameter copyWith({ String? type, @@ -232,6 +236,7 @@ class Parameter { bool? isDartMap, bool? isDartSet, bool? isFinal, + bool? isCommonWithDifferentNullability, }) => Parameter( type: type ?? this.type, @@ -248,6 +253,8 @@ class Parameter { isFinal: isFinal ?? this.isFinal, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, + isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? + this.isCommonWithDifferentNullability, ); @override @@ -283,6 +290,7 @@ class LocalParameter extends Parameter { required List decorators, required String doc, required bool isPossiblyDartCollection, + required bool isCommonWithDifferentNullability, }) : super( name: name, type: type, @@ -297,6 +305,7 @@ class LocalParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, + isCommonWithDifferentNullability: isCommonWithDifferentNullability, ); LocalParameter.fromParameter(Parameter p) @@ -313,6 +322,7 @@ class LocalParameter extends Parameter { decorators: p.decorators, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, + isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, ); @override @@ -346,6 +356,7 @@ class CallbackParameter extends Parameter { required this.parameters, required String doc, required bool isPossiblyDartCollection, + required bool isCommonWithDifferentNullability, }) : super( name: name, type: type, @@ -360,6 +371,7 @@ class CallbackParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, + isCommonWithDifferentNullability: isCommonWithDifferentNullability, ); final ParametersTemplate parameters; diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index 1c0a11ea..1052101b 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -31,6 +31,7 @@ class Property { required this.isDartMap, required this.isDartSet, required this.isPossiblyDartCollection, + required this.isCommonWithDifferentNullability, }) : type = type ?? 'dynamic'; static Future fromParameter( @@ -60,6 +61,7 @@ class Property { defaultValueSource: defaultValue, hasJsonKey: element.hasJsonKey, isPossiblyDartCollection: element.type.isPossiblyDartCollection, + isCommonWithDifferentNullability: false, ); } @@ -75,6 +77,7 @@ class Property { final bool hasJsonKey; final String doc; final bool isPossiblyDartCollection; + final bool isCommonWithDifferentNullability; @override String toString() { @@ -135,6 +138,7 @@ class Property { bool? hasJsonKey, String? doc, bool? isPossiblyDartCollection, + bool? isCommonWithDifferentNullability, }) { return Property( type: type ?? this.type, @@ -150,6 +154,8 @@ class Property { isDartSet: isDartSet ?? this.isDartSet, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, + isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? + this.isCommonWithDifferentNullability, ); } } diff --git a/packages/freezed/lib/src/templates/prototypes.dart b/packages/freezed/lib/src/templates/prototypes.dart index ccba9f73..758df8f7 100644 --- a/packages/freezed/lib/src/templates/prototypes.dart +++ b/packages/freezed/lib/src/templates/prototypes.dart @@ -127,6 +127,7 @@ String _mapPrototype( // TODO: do we want to support freezed classes that implements MapView/ListView? isPossiblyDartCollection: false, showDefaultValue: false, + isCommonWithDifferentNullability: false, ), ]); }, @@ -191,6 +192,7 @@ String _unionPrototype( defaultValueSource: '', doc: '', isPossiblyDartCollection: false, + isCommonWithDifferentNullability: false, ); if (constructor.isDefault) { diff --git a/packages/freezed/pubspec.yaml b/packages/freezed/pubspec.yaml index 422c8464..f008b389 100644 --- a/packages/freezed/pubspec.yaml +++ b/packages/freezed/pubspec.yaml @@ -6,10 +6,10 @@ version: 2.1.0+1 homepage: https://github.com/rrousselGit/freezed environment: - sdk: '>=2.17.0 <3.0.0' + sdk: ">=2.17.0 <3.0.0" dependencies: - analyzer: ">=4.2.0 <5.0.0" + analyzer: ">=4.6.0 <5.0.0" build: ^2.0.0 build_config: ^1.0.0 collection: ^1.15.0 diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 62b8b671..84600f9b 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -64,6 +64,14 @@ class SharedParam with _$SharedParam { const factory SharedParam.named(String a, int c) = SharedParam1; } +@freezed +class SharedParamNullable with _$SharedParamNullable { + const factory SharedParamNullable(String a, String b, int c) = + SharedParamNullable0; + const factory SharedParamNullable.named(String? a, String b, int d) = + SharedParamNullable1; +} + @freezed class Complex with _$Complex { @Assert("a != ''", '"Hello"') diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index 6119d7ae..b41dae15 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -504,8 +504,48 @@ void main() { } '''), throwsCompileError); }); + }); + + group('SharedParamNullable', () { + test('has the common properties available', () { + SharedParamNullable value = SharedParamNullable('a', 'b', 42); + expect(value.a, 'a'); + + value = SharedParamNullable.named('b', 'c', 24); + expect(value.a, 'b'); + }); + + test( + "copy doesn't have shared params with different nullability", + () async { + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamNullable('a', 'b', 42); + param.copyWith(a: '2'); +} +'''), throwsCompileError); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamNullable('a', 'b', 42); + param.copyWith(b: '1'); +} +'''), completes); - // TODO: shared property name but different type + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamNullable('a', 'b', 42); + param.copyWith(c: 42); +} +'''), throwsCompileError); + }, + ); }); test('Can have a named constructor and a property using the same name', () { From f7b34896e98e95ba38605687fade4227ff438616 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Mon, 15 Aug 2022 23:08:41 +0200 Subject: [PATCH 02/23] style: fix format --- packages/freezed/lib/src/freezed_generator.dart | 4 ---- packages/freezed/test/integration/multiple_constructors.dart | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index af5245fe..3411e102 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -274,10 +274,6 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C final isNullable = parameter.isNullable || anyMatchingPropertyIsNullable; - if (parameter.isNullable != isNullable) { - print(parameter.name); - } - return parameter.copyWith( isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, isNullable: isNullable, diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 84600f9b..8d15dc28 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -68,7 +68,7 @@ class SharedParam with _$SharedParam { class SharedParamNullable with _$SharedParamNullable { const factory SharedParamNullable(String a, String b, int c) = SharedParamNullable0; - const factory SharedParamNullable.named(String? a, String b, int d) = + const factory SharedParamNullable.named(String? a, String b, int d) = SharedParamNullable1; } From 3de63e5c06070dbec60192ac6d890ae183378746 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Tue, 16 Aug 2022 02:27:22 +0200 Subject: [PATCH 03/23] feat: common properties with different nullability are non-null in copyWith --- .../freezed/lib/src/freezed_generator.dart | 14 +--- .../freezed/lib/src/templates/copy_with.dart | 67 +++++++++++-------- packages/freezed/lib/src/utils.dart | 6 ++ .../test/multiple_constructors_test.dart | 36 +++++++++- 4 files changed, 83 insertions(+), 40 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 3411e102..9f548e6b 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -261,8 +261,8 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C final matchingParameter = constructor.parameters.allParameters.firstWhereOrNull((p) { return p.name == parameter.name && - _typeStringWithoutNullability(p.type) == - _typeStringWithoutNullability(parameter.type); + typeStringWithoutNullability(p.type) == + typeStringWithoutNullability(parameter.type); }); if (matchingParameter == null) return null; @@ -288,12 +288,6 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C .toList(); } - String? _typeStringWithoutNullability(String? type) { - return type?.endsWith('?') == true - ? type?.substring(0, type.length - 1) - : type; - } - Future> _parseConstructorsNeedsGeneration( BuildStep buildStep, ClassElement element, @@ -627,9 +621,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C ).toList(), genericsDefinition: data.genericsDefinitionTemplate, genericsParameter: data.genericsParameterTemplate, - allProperties: commonProperties - .whereNot((element) => element.isCommonWithDifferentNullability) - .toList(), + allProperties: commonProperties, data: data, ); diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index e7566f2c..a79f2169 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -1,6 +1,6 @@ -import 'package:collection/collection.dart'; import 'package:freezed/src/templates/parameter_template.dart'; import 'package:freezed/src/templates/properties.dart'; +import 'package:freezed/src/utils.dart'; import '../models.dart'; @@ -66,28 +66,25 @@ ${_abstractDeepCopyMethods().join()} final body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: commonProperties - .map((e) { - return Parameter( - decorators: e.decorators, - name: e.name, - isNullable: false, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - showDefaultValue: false, - isRequired: false, - defaultValueSource: '', - type: e.type, - doc: e.doc, - isPossiblyDartCollection: e.isPossiblyDartCollection, - isCommonWithDifferentNullability: - e.isCommonWithDifferentNullability, - ); - }) - .whereNot((element) => element.isCommonWithDifferentNullability) - .toList(), + namedParameters: commonProperties.map((e) { + return Parameter( + decorators: e.decorators, + name: e.name, + isNullable: false, + isFinal: false, + isDartList: false, + isDartMap: false, + isDartSet: false, + showDefaultValue: false, + isRequired: false, + defaultValueSource: '', + type: e.type, + doc: e.doc, + isPossiblyDartCollection: e.isPossiblyDartCollection, + isCommonWithDifferentNullability: + e.isCommonWithDifferentNullability, + ); + }).toList(), ), returnType: '_value.copyWith', ); @@ -139,7 +136,11 @@ ${_deepCopyMethods().join()} required List properties, }) { final parameters = properties.map((p) { - return '${p.decorators.join()} ${p.type} ${p.name}'; + final type = p.isCommonWithDifferentNullability + ? typeStringWithoutNullability(p.type) + : p.type; + + return '${p.decorators.join()} $type ${p.name}'; }).join(','); return _maybeOverride(''' @@ -203,10 +204,18 @@ $s'''; data.makeCollectionsImmutable) { propertyName = '_$propertyName'; } - var ternary = - '${p.name} == freezed ? $accessor.$propertyName : ${p.name} '; + final type = p.isCommonWithDifferentNullability + ? typeStringWithoutNullability(p.type) + : p.type; + var ternary = '${p.name} == freezed ? $accessor.$propertyName '; + + if (p.isCommonWithDifferentNullability) { + ternary += 'as $type '; + } + + ternary += ': ${p.name} '; if (p.type != 'Object?' && p.type != null) { - ternary += _ignoreLints('as ${p.type}'); + ternary += _ignoreLints('as $type'); } return '$ternary,'; } @@ -236,7 +245,9 @@ $constructorParameters required String methodName, }) { final parameters = properties.map((p) { - return 'Object? ${p.name} = freezed,'; + final type = p.isCommonWithDifferentNullability ? 'Object' : 'Object?'; + + return '$type ${p.name} = freezed,'; }).join(); return '\$Res $methodName({$parameters})'; diff --git a/packages/freezed/lib/src/utils.dart b/packages/freezed/lib/src/utils.dart index 39687221..fbe34097 100644 --- a/packages/freezed/lib/src/utils.dart +++ b/packages/freezed/lib/src/utils.dart @@ -71,3 +71,9 @@ String _fixCase(String input, String separator) => return lower; }); + +String? typeStringWithoutNullability(String? type) { + return type?.endsWith('?') == true + ? type?.substring(0, type.length - 1) + : type; +} diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index b41dae15..8b153987 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -515,8 +515,33 @@ void main() { expect(value.a, 'b'); }); + test('copy common updates when non null', () { + SharedParamNullable value = SharedParamNullable('a', 'b', 42); + expect(value.a, 'a'); + + value = value.copyWith(a: 'b'); + expect(value.a, 'b'); + }); + + test('copy common updates when null', () { + SharedParamNullable value = SharedParamNullable.named(null, 'b', 42); + expect(value.a, null); + + value = value.copyWith(a: 'a'); + expect(value.a, 'a'); + }); + + test('copy on null common variable', () { + SharedParamNullable value = SharedParamNullable.named(null, 'b', 42); + expect(value.a, null); + + value = value.copyWith(b: 'c'); + expect(value.a, null); + expect(value.b, 'c'); + }); + test( - "copy doesn't have shared params with different nullability", + 'copy has shared params with different nullability available as non-null', () async { await expectLater(compile(r''' import 'multiple_constructors.dart'; @@ -525,6 +550,15 @@ void main() { final param = SharedParamNullable('a', 'b', 42); param.copyWith(a: '2'); } +'''), completes); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamNullable('a', 'b', 42); + param.copyWith(a: null); +} '''), throwsCompileError); await expectLater(compile(r''' From 78d8526c103fccd8039c5972d9e15704d2e1ff4a Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Wed, 17 Aug 2022 03:50:46 +0200 Subject: [PATCH 04/23] feat: properties with common super types have getters in base mixin --- .../freezed/lib/src/freezed_generator.dart | 91 ++++++++++--------- .../lib/src/templates/abstract_template.dart | 4 +- .../lib/src/templates/concrete_template.dart | 1 + .../freezed/lib/src/templates/copy_with.dart | 12 +-- .../lib/src/templates/parameter_template.dart | 10 ++ .../freezed/lib/src/templates/properties.dart | 27 +++++- .../freezed/lib/src/templates/prototypes.dart | 2 + packages/freezed/lib/src/utils.dart | 6 -- .../integration/multiple_constructors.dart | 11 ++- .../integration/single_class_constructor.dart | 2 +- .../test/multiple_constructors_test.dart | 53 ++++------- 11 files changed, 118 insertions(+), 101 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 9f548e6b..9314f8a7 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -128,29 +128,19 @@ class FreezedGenerator extends ParserGenerator { List _commonProperties( List constructorsNeedsGeneration, ) { - final commonParameters = - _commonParametersBetweenAllConstructors(constructorsNeedsGeneration); - - return [ - for (final commonParameter in commonParameters) - Property( - decorators: commonParameter.decorators, - name: commonParameter.name, - isFinal: commonParameter.isFinal, - doc: commonParameter.doc, - type: commonParameter.type, - defaultValueSource: commonParameter.defaultValueSource, - isNullable: commonParameter.isNullable, - isDartList: commonParameter.isDartList, - isDartMap: commonParameter.isDartMap, - isDartSet: commonParameter.isDartSet, - isPossiblyDartCollection: commonParameter.isPossiblyDartCollection, - // TODO: support hasJsonKey - hasJsonKey: false, - isCommonWithDifferentNullability: - commonParameter.isCommonWithDifferentNullability, - ), - ]; + return _commonParametersBetweenAllConstructors( + constructorsNeedsGeneration, + allowCommonSuperType: false, + ).map(Property.fromParameter).toList(); + } + + List _commonGetters( + List constructorsNeedsGeneration, + ) { + return _commonParametersBetweenAllConstructors( + constructorsNeedsGeneration, + allowCommonSuperType: true, + ).map(Property.fromParameter).toList(); } void _assertValidClassUsage(ClassElement element) { @@ -250,38 +240,47 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } List _commonParametersBetweenAllConstructors( - List constructorsNeedsGeneration, - ) { + List constructorsNeedsGeneration, { + required bool allowCommonSuperType, + }) { return constructorsNeedsGeneration.first.parameters.allParameters .map((parameter) { var anyMatchingPropertyIsFinal = false; - var anyMatchingPropertyIsNullable = false; + var isCommonWithDifferentNullability = false; - for (final constructor in constructorsNeedsGeneration) { - final matchingParameter = - constructor.parameters.allParameters.firstWhereOrNull((p) { - return p.name == parameter.name && - typeStringWithoutNullability(p.type) == - typeStringWithoutNullability(parameter.type); - }); + DartType? commonType; + + for (final constructor in constructorsNeedsGeneration.skip(1)) { + final matchingParameter = constructor.parameters.allParameters + .firstWhereOrNull((p) => p.name == parameter.name); if (matchingParameter == null) return null; + + final commonTypeWithMatch = + parameter.parameterElement!.library!.typeSystem.leastUpperBound( + parameter.parameterElement!.type, + matchingParameter.parameterElement!.type, + ); + + if (commonTypeWithMatch.isDartCoreObject) return null; + + if (!allowCommonSuperType && + commonTypeWithMatch.getDisplayString(withNullability: false) != + parameter.type?.replaceAll(r'?$', '')) return null; + + if (commonType != null && commonType != commonTypeWithMatch) + return null; + + commonType = commonTypeWithMatch; if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - if (matchingParameter.isNullable) - anyMatchingPropertyIsNullable = true; + if (parameter.isNullable != matchingParameter.isNullable) + isCommonWithDifferentNullability = true; } - final isNullable = - parameter.isNullable || anyMatchingPropertyIsNullable; - return parameter.copyWith( isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, - isNullable: isNullable, - type: isNullable && (parameter.type?.endsWith('?') == false) - ? '${parameter.type}?' - : parameter.type, - isCommonWithDifferentNullability: - parameter.isNullable != isNullable, + type: commonType?.getDisplayString(withNullability: true), + isCommonWithDifferentNullability: isCommonWithDifferentNullability, ); }) .whereNotNull() @@ -326,7 +325,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C escapedName: _escapedName(element, constructor), impliedProperties: [ for (final parameter in constructor.parameters) - await Property.fromParameter( + await Property.fromParameterElement( parameter, buildStep, addImplicitFinal: options.addImplicitFinal, @@ -610,6 +609,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } final commonProperties = _commonProperties(data.constructors); + final commonGetters = _commonGetters(data.constructors); final commonCopyWith = !data.generateCopyWith ? null @@ -628,6 +628,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C yield Abstract( data: data, copyWith: commonCopyWith, + commonGetters: commonGetters, commonProperties: commonProperties, ); diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index c588923e..02127e88 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -9,15 +9,17 @@ class Abstract { required this.data, required this.copyWith, required this.commonProperties, + required this.commonGetters, }); final Data data; final CopyWith? copyWith; final List commonProperties; + final List commonGetters; @override String toString() { - final abstractProperties = commonProperties + final abstractProperties = commonGetters .expand((e) => [ e.unimplementedGetter, if (!e.isFinal) e.unimplementedSetter, diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index 52099b90..cf0e5638 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -136,6 +136,7 @@ ${copyWith?.abstractCopyWithGetter ?? ''} isPossiblyDartCollection: false, showDefaultValue: false, isCommonWithDifferentNullability: false, + parameterElement: null, ); parameters = ParametersTemplate( diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index a79f2169..dd5a996e 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -1,6 +1,5 @@ import 'package:freezed/src/templates/parameter_template.dart'; import 'package:freezed/src/templates/properties.dart'; -import 'package:freezed/src/utils.dart'; import '../models.dart'; @@ -83,6 +82,7 @@ ${_abstractDeepCopyMethods().join()} isPossiblyDartCollection: e.isPossiblyDartCollection, isCommonWithDifferentNullability: e.isCommonWithDifferentNullability, + parameterElement: null, ); }).toList(), ), @@ -137,10 +137,10 @@ ${_deepCopyMethods().join()} }) { final parameters = properties.map((p) { final type = p.isCommonWithDifferentNullability - ? typeStringWithoutNullability(p.type) + ? p.type.replaceFirst(RegExp(r'\?$'), '') : p.type; - return '${p.decorators.join()} $type ${p.name}'; + return '${p.decorators.join()} covariant $type ${p.name}'; }).join(','); return _maybeOverride(''' @@ -205,7 +205,7 @@ $s'''; propertyName = '_$propertyName'; } final type = p.isCommonWithDifferentNullability - ? typeStringWithoutNullability(p.type) + ? p.type!.replaceFirst(RegExp(r'\?$'), '') : p.type; var ternary = '${p.name} == freezed ? $accessor.$propertyName '; @@ -245,9 +245,7 @@ $constructorParameters required String methodName, }) { final parameters = properties.map((p) { - final type = p.isCommonWithDifferentNullability ? 'Object' : 'Object?'; - - return '$type ${p.name} = freezed,'; + return 'Object? ${p.name} = freezed,'; }).join(); return '\$Res $methodName({$parameters})'; diff --git a/packages/freezed/lib/src/templates/parameter_template.dart b/packages/freezed/lib/src/templates/parameter_template.dart index 88d0d7e7..5a143947 100644 --- a/packages/freezed/lib/src/templates/parameter_template.dart +++ b/packages/freezed/lib/src/templates/parameter_template.dart @@ -83,6 +83,7 @@ class ParametersTemplate { isPossiblyDartCollection: e.type.isPossiblyDartCollection, showDefaultValue: true, isCommonWithDifferentNullability: false, + parameterElement: e, ); if (isAssignedToThis) return LocalParameter.fromParameter(value); @@ -186,6 +187,7 @@ class Parameter { required this.isPossiblyDartCollection, required this.showDefaultValue, required this.isCommonWithDifferentNullability, + required this.parameterElement, }); Parameter.fromParameter(Parameter p) @@ -204,6 +206,7 @@ class Parameter { doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, + parameterElement: p.parameterElement, ); final String? type; @@ -220,6 +223,7 @@ class Parameter { final bool isFinal; final String doc; final bool isCommonWithDifferentNullability; + final ParameterElement? parameterElement; Parameter copyWith({ String? type, @@ -255,6 +259,7 @@ class Parameter { isPossiblyDartCollection ?? this.isPossiblyDartCollection, isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? this.isCommonWithDifferentNullability, + parameterElement: parameterElement, ); @override @@ -291,6 +296,7 @@ class LocalParameter extends Parameter { required String doc, required bool isPossiblyDartCollection, required bool isCommonWithDifferentNullability, + required ParameterElement? parameterElement, }) : super( name: name, type: type, @@ -306,6 +312,7 @@ class LocalParameter extends Parameter { doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, isCommonWithDifferentNullability: isCommonWithDifferentNullability, + parameterElement: parameterElement, ); LocalParameter.fromParameter(Parameter p) @@ -323,6 +330,7 @@ class LocalParameter extends Parameter { doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, + parameterElement: p.parameterElement, ); @override @@ -357,6 +365,7 @@ class CallbackParameter extends Parameter { required String doc, required bool isPossiblyDartCollection, required bool isCommonWithDifferentNullability, + required ParameterElement? parameterElement, }) : super( name: name, type: type, @@ -372,6 +381,7 @@ class CallbackParameter extends Parameter { doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, isCommonWithDifferentNullability: isCommonWithDifferentNullability, + parameterElement: parameterElement, ); final ParametersTemplate parameters; diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index 1052101b..9d4f118b 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -2,6 +2,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build/build.dart'; +import 'package:freezed/src/templates/parameter_template.dart'; import 'package:source_gen/source_gen.dart'; import '../utils.dart'; @@ -32,9 +33,29 @@ class Property { required this.isDartSet, required this.isPossiblyDartCollection, required this.isCommonWithDifferentNullability, + required this.parameterElement, }) : type = type ?? 'dynamic'; - static Future fromParameter( + Property.fromParameter(Parameter p) + : this( + decorators: p.decorators, + name: p.name, + isFinal: p.isFinal, + doc: p.doc, + type: p.type, + defaultValueSource: p.defaultValueSource, + isNullable: p.isNullable, + isDartList: p.isDartList, + isDartMap: p.isDartMap, + isDartSet: p.isDartSet, + isPossiblyDartCollection: p.isPossiblyDartCollection, + // TODO: support hasJsonKey + hasJsonKey: false, + isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, + parameterElement: p.parameterElement, + ); + + static Future fromParameterElement( ParameterElement element, BuildStep buildStep, { required bool addImplicitFinal, @@ -62,6 +83,7 @@ class Property { hasJsonKey: element.hasJsonKey, isPossiblyDartCollection: element.type.isPossiblyDartCollection, isCommonWithDifferentNullability: false, + parameterElement: element, ); } @@ -78,6 +100,7 @@ class Property { final String doc; final bool isPossiblyDartCollection; final bool isCommonWithDifferentNullability; + final ParameterElement? parameterElement; @override String toString() { @@ -139,6 +162,7 @@ class Property { String? doc, bool? isPossiblyDartCollection, bool? isCommonWithDifferentNullability, + ParameterElement? parameterElement, }) { return Property( type: type ?? this.type, @@ -156,6 +180,7 @@ class Property { isPossiblyDartCollection ?? this.isPossiblyDartCollection, isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? this.isCommonWithDifferentNullability, + parameterElement: parameterElement ?? this.parameterElement, ); } } diff --git a/packages/freezed/lib/src/templates/prototypes.dart b/packages/freezed/lib/src/templates/prototypes.dart index 758df8f7..6db70748 100644 --- a/packages/freezed/lib/src/templates/prototypes.dart +++ b/packages/freezed/lib/src/templates/prototypes.dart @@ -128,6 +128,7 @@ String _mapPrototype( isPossiblyDartCollection: false, showDefaultValue: false, isCommonWithDifferentNullability: false, + parameterElement: null, ), ]); }, @@ -193,6 +194,7 @@ String _unionPrototype( doc: '', isPossiblyDartCollection: false, isCommonWithDifferentNullability: false, + parameterElement: null, ); if (constructor.isDefault) { diff --git a/packages/freezed/lib/src/utils.dart b/packages/freezed/lib/src/utils.dart index fbe34097..39687221 100644 --- a/packages/freezed/lib/src/utils.dart +++ b/packages/freezed/lib/src/utils.dart @@ -71,9 +71,3 @@ String _fixCase(String input, String separator) => return lower; }); - -String? typeStringWithoutNullability(String? type) { - return type?.endsWith('?') == true - ? type?.substring(0, type.length - 1) - : type; -} diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 8d15dc28..5919bf2c 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -65,11 +65,12 @@ class SharedParam with _$SharedParam { } @freezed -class SharedParamNullable with _$SharedParamNullable { - const factory SharedParamNullable(String a, String b, int c) = - SharedParamNullable0; - const factory SharedParamNullable.named(String? a, String b, int d) = - SharedParamNullable1; +class SharedParamCommonSuperType with _$SharedParamCommonSuperType { + const factory SharedParamCommonSuperType(String a, int b, int c) = + SharedParamCommonSuperType0; + + const factory SharedParamCommonSuperType.named(String? a, double b, int d) = + SharedParamCommonSuperType1; } @freezed diff --git a/packages/freezed/test/integration/single_class_constructor.dart b/packages/freezed/test/integration/single_class_constructor.dart index 3568c4a1..f5fee495 100644 --- a/packages/freezed/test/integration/single_class_constructor.dart +++ b/packages/freezed/test/integration/single_class_constructor.dart @@ -450,7 +450,7 @@ class NullDefault with _$NullDefault { class ExplicitConstDefault with _$ExplicitConstDefault { factory ExplicitConstDefault( //ignore: unnecessary_const - [@Default(const []) List value]) = _ExplicitConstDefault; + [@Default([]) List value]) = _ExplicitConstDefault; } @freezed diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index 8b153987..0d5cd62f 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -506,40 +506,27 @@ void main() { }); }); - group('SharedParamNullable', () { + group('SharedParamCommonSuperType', () { test('has the common properties available', () { - SharedParamNullable value = SharedParamNullable('a', 'b', 42); + SharedParamCommonSuperType value = + SharedParamCommonSuperType('a', 1337, 42); expect(value.a, 'a'); + expect(value.b, 1337); - value = SharedParamNullable.named('b', 'c', 24); + value = SharedParamCommonSuperType.named('b', 2.4, 24); expect(value.a, 'b'); + expect(value.b, 2.4); }); - test('copy common updates when non null', () { - SharedParamNullable value = SharedParamNullable('a', 'b', 42); + test('copy has different nullability available', () { + SharedParamCommonSuperType value = + SharedParamCommonSuperType('a', 1337, 42); expect(value.a, 'a'); value = value.copyWith(a: 'b'); expect(value.a, 'b'); }); - test('copy common updates when null', () { - SharedParamNullable value = SharedParamNullable.named(null, 'b', 42); - expect(value.a, null); - - value = value.copyWith(a: 'a'); - expect(value.a, 'a'); - }); - - test('copy on null common variable', () { - SharedParamNullable value = SharedParamNullable.named(null, 'b', 42); - expect(value.a, null); - - value = value.copyWith(b: 'c'); - expect(value.a, null); - expect(value.b, 'c'); - }); - test( 'copy has shared params with different nullability available as non-null', () async { @@ -547,7 +534,7 @@ void main() { import 'multiple_constructors.dart'; void main() { - final param = SharedParamNullable('a', 'b', 42); + final param = SharedParamCommonSuperType('a', 1337, 42); param.copyWith(a: '2'); } '''), completes); @@ -556,26 +543,22 @@ void main() { import 'multiple_constructors.dart'; void main() { - final param = SharedParamNullable('a', 'b', 42); + final param = SharedParamCommonSuperType('a', 1337, 42); param.copyWith(a: null); } '''), throwsCompileError); + }, + ); + test( + 'copy does not have shared params with common super type available', + () async { await expectLater(compile(r''' import 'multiple_constructors.dart'; void main() { - final param = SharedParamNullable('a', 'b', 42); - param.copyWith(b: '1'); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamNullable('a', 'b', 42); - param.copyWith(c: 42); + final param = SharedParamCommonSuperType('a', 'b', 42); + param.copyWith(b: 42); } '''), throwsCompileError); }, From 29012d02a1b08354efd3699c8299f96751b80a02 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Thu, 18 Aug 2022 20:38:19 +0200 Subject: [PATCH 05/23] feat: properties with common subtypes are available in copyWith --- .../freezed/lib/src/freezed_generator.dart | 112 +++++++++--------- .../lib/src/templates/abstract_template.dart | 8 +- .../lib/src/templates/concrete_template.dart | 3 +- .../freezed/lib/src/templates/copy_with.dart | 61 +++++----- .../lib/src/templates/parameter_template.dart | 34 ++++-- .../freezed/lib/src/templates/properties.dart | 32 ++--- .../freezed/lib/src/templates/prototypes.dart | 6 +- .../integration/multiple_constructors.dart | 28 ++++- .../integration/single_class_constructor.dart | 2 +- .../test/multiple_constructors_test.dart | 87 +++++++++++--- 10 files changed, 233 insertions(+), 140 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 9314f8a7..cab5a90f 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -128,19 +128,9 @@ class FreezedGenerator extends ParserGenerator { List _commonProperties( List constructorsNeedsGeneration, ) { - return _commonParametersBetweenAllConstructors( - constructorsNeedsGeneration, - allowCommonSuperType: false, - ).map(Property.fromParameter).toList(); - } - - List _commonGetters( - List constructorsNeedsGeneration, - ) { - return _commonParametersBetweenAllConstructors( - constructorsNeedsGeneration, - allowCommonSuperType: true, - ).map(Property.fromParameter).toList(); + return _commonPropertiesBetweenAllConstructors(constructorsNeedsGeneration) + .map(Property.fromParameter) + .toList(); } void _assertValidClassUsage(ClassElement element) { @@ -239,52 +229,63 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return false; } - List _commonParametersBetweenAllConstructors( - List constructorsNeedsGeneration, { - required bool allowCommonSuperType, - }) { + Iterable _commonPropertiesBetweenAllConstructors( + List constructorsNeedsGeneration, + ) { return constructorsNeedsGeneration.first.parameters.allParameters .map((parameter) { - var anyMatchingPropertyIsFinal = false; - var isCommonWithDifferentNullability = false; + var anyMatchingPropertyIsFinal = false; + var commonSupertype = parameter.parameterElement!.type; + var commonSubtype = parameter.parameterElement?.type; - DartType? commonType; + final library = parameter.parameterElement!.library!; - for (final constructor in constructorsNeedsGeneration.skip(1)) { - final matchingParameter = constructor.parameters.allParameters - .firstWhereOrNull((p) => p.name == parameter.name); + for (final constructor in constructorsNeedsGeneration.skip(1)) { + final matchingParameter = constructor.parameters.allParameters + .firstWhereOrNull((p) => p.name == parameter.name); - if (matchingParameter == null) return null; + if (matchingParameter == null) return null; - final commonTypeWithMatch = - parameter.parameterElement!.library!.typeSystem.leastUpperBound( - parameter.parameterElement!.type, - matchingParameter.parameterElement!.type, - ); + final matchingParameterType = matchingParameter.parameterElement!.type; - if (commonTypeWithMatch.isDartCoreObject) return null; + commonSupertype = library.typeSystem.leastUpperBound( + commonSupertype, + matchingParameterType, + ); - if (!allowCommonSuperType && - commonTypeWithMatch.getDisplayString(withNullability: false) != - parameter.type?.replaceAll(r'?$', '')) return null; + if (commonSupertype + .getDisplayString(withNullability: true) + .contains('dynamic')) return null; - if (commonType != null && commonType != commonTypeWithMatch) - return null; + if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - commonType = commonTypeWithMatch; - if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - if (parameter.isNullable != matchingParameter.isNullable) - isCommonWithDifferentNullability = true; + if (commonSubtype != null) { + if (library.typeSystem + .isSubtypeOf(matchingParameterType, commonSubtype)) { + commonSubtype = matchingParameterType; + } else if (!library.typeSystem + .isSubtypeOf(commonSubtype, matchingParameterType)) { + commonSubtype = null; } + } + } - return parameter.copyWith( - isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, - type: commonType?.getDisplayString(withNullability: true), - isCommonWithDifferentNullability: isCommonWithDifferentNullability, - ); - }) - .whereNotNull() - .toList(); + return parameter.copyWith( + isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, + commonSupertype: resolveFullTypeStringFrom( + library, + commonSupertype, + withNullability: true, + ), + commonSubtype: commonSubtype?.let( + (cs) => resolveFullTypeStringFrom( + library, + cs, + withNullability: true, + ), + ), + ); + }).whereNotNull(); } Future> _parseConstructorsNeedsGeneration( @@ -452,8 +453,8 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } Iterable _commonCloneableProperties( - List constructors, - List commonProperties, + Iterable constructors, + Iterable commonProperties, ) sync* { for (final cloneableProperty in constructors.first.cloneableProperties) { for (final commonProperty in commonProperties) { @@ -609,7 +610,8 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } final commonProperties = _commonProperties(data.constructors); - final commonGetters = _commonGetters(data.constructors); + final commonCopyableProperties = + commonProperties.where((p) => p.isCopyable); final commonCopyWith = !data.generateCopyWith ? null @@ -617,18 +619,17 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C clonedClassName: data.name, cloneableProperties: _commonCloneableProperties( data.constructors, - commonProperties, + commonCopyableProperties, ).toList(), genericsDefinition: data.genericsDefinitionTemplate, genericsParameter: data.genericsParameterTemplate, - allProperties: commonProperties, + allProperties: commonCopyableProperties, data: data, ); yield Abstract( data: data, copyWith: commonCopyWith, - commonGetters: commonGetters, commonProperties: commonProperties, ); @@ -845,3 +846,8 @@ String? parseLateGetterSource(String source) { } return null; } + +extension Let on T { + @pragma('vm:prefer-inline') + R let(R Function(T) f) => f(this); +} diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 02127e88..ae934f77 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -9,17 +9,15 @@ class Abstract { required this.data, required this.copyWith, required this.commonProperties, - required this.commonGetters, }); final Data data; final CopyWith? copyWith; - final List commonProperties; - final List commonGetters; + final Iterable commonProperties; @override String toString() { - final abstractProperties = commonGetters + final abstractProperties = commonProperties .expand((e) => [ e.unimplementedGetter, if (!e.isFinal) e.unimplementedSetter, @@ -43,7 +41,7 @@ ${copyWith?.abstractCopyWithGetter ?? ''} ${copyWith?.interface ?? ''} -${copyWith?.commonContreteImpl(commonProperties) ?? ''} +${copyWith?.commonContreteImpl ?? ''} '''; } diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index cf0e5638..357761a9 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -135,7 +135,8 @@ ${copyWith?.abstractCopyWithGetter ?? ''} doc: '', isPossiblyDartCollection: false, showDefaultValue: false, - isCommonWithDifferentNullability: false, + commonSupertype: null, + commonSubtype: null, parameterElement: null, ); diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index dd5a996e..478f6af8 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -24,7 +24,7 @@ class CopyWith { final String clonedClassName; final GenericsDefinitionTemplate genericsDefinition; final GenericsParameterTemplate genericsParameter; - final List allProperties; + final Iterable allProperties; final List cloneableProperties; final CopyWith? parent; final Data data; @@ -51,9 +51,7 @@ ${_abstractDeepCopyMethods().join()} return parent != null && parent!.allProperties.isNotEmpty; } - String commonContreteImpl( - List commonProperties, - ) { + String get commonContreteImpl { var copyWith = ''; if (allProperties.isNotEmpty) { @@ -65,26 +63,26 @@ ${_abstractDeepCopyMethods().join()} final body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: commonProperties.map((e) { - return Parameter( - decorators: e.decorators, - name: e.name, - isNullable: false, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - showDefaultValue: false, - isRequired: false, - defaultValueSource: '', - type: e.type, - doc: e.doc, - isPossiblyDartCollection: e.isPossiblyDartCollection, - isCommonWithDifferentNullability: - e.isCommonWithDifferentNullability, - parameterElement: null, - ); - }).toList(), + namedParameters: allProperties + .map((e) => Parameter( + decorators: e.decorators, + name: e.name, + isNullable: false, + isFinal: false, + isDartList: false, + isDartMap: false, + isDartSet: false, + showDefaultValue: false, + isRequired: false, + defaultValueSource: '', + type: e.commonSupertype ?? e.type, + doc: e.doc, + isPossiblyDartCollection: e.isPossiblyDartCollection, + commonSupertype: e.commonSupertype, + commonSubtype: e.commonSubtype, + parameterElement: null, + )) + .toList(), ), returnType: '_value.copyWith', ); @@ -133,12 +131,10 @@ ${_deepCopyMethods().join()} String _copyWithProtypeFor({ required String methodName, - required List properties, + required Iterable properties, }) { final parameters = properties.map((p) { - final type = p.isCommonWithDifferentNullability - ? p.type.replaceFirst(RegExp(r'\?$'), '') - : p.type; + final type = p.commonSubtype ?? p.type; return '${p.decorators.join()} covariant $type ${p.name}'; }).join(','); @@ -204,12 +200,11 @@ $s'''; data.makeCollectionsImmutable) { propertyName = '_$propertyName'; } - final type = p.isCommonWithDifferentNullability - ? p.type!.replaceFirst(RegExp(r'\?$'), '') - : p.type; + var ternary = '${p.name} == freezed ? $accessor.$propertyName '; - if (p.isCommonWithDifferentNullability) { + final type = p.commonSubtype ?? p.type; + if (p.commonSubtype != null && p.type != p.commonSubtype) { ternary += 'as $type '; } @@ -241,7 +236,7 @@ $constructorParameters } String _concreteCopyWithPrototype({ - required List properties, + required Iterable properties, required String methodName, }) { final parameters = properties.map((p) { diff --git a/packages/freezed/lib/src/templates/parameter_template.dart b/packages/freezed/lib/src/templates/parameter_template.dart index 5a143947..2aed242c 100644 --- a/packages/freezed/lib/src/templates/parameter_template.dart +++ b/packages/freezed/lib/src/templates/parameter_template.dart @@ -82,7 +82,8 @@ class ParametersTemplate { doc: await documentationOfParameter(e, buildStep), isPossiblyDartCollection: e.type.isPossiblyDartCollection, showDefaultValue: true, - isCommonWithDifferentNullability: false, + commonSupertype: null, + commonSubtype: null, parameterElement: e, ); @@ -186,7 +187,8 @@ class Parameter { required this.isFinal, required this.isPossiblyDartCollection, required this.showDefaultValue, - required this.isCommonWithDifferentNullability, + required this.commonSupertype, + required this.commonSubtype, required this.parameterElement, }); @@ -205,7 +207,8 @@ class Parameter { showDefaultValue: p.showDefaultValue, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, - isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, + commonSubtype: p.commonSubtype, + commonSupertype: p.commonSupertype, parameterElement: p.parameterElement, ); @@ -222,7 +225,8 @@ class Parameter { final bool isPossiblyDartCollection; final bool isFinal; final String doc; - final bool isCommonWithDifferentNullability; + final String? commonSupertype; + final String? commonSubtype; final ParameterElement? parameterElement; Parameter copyWith({ @@ -240,7 +244,8 @@ class Parameter { bool? isDartMap, bool? isDartSet, bool? isFinal, - bool? isCommonWithDifferentNullability, + String? commonSupertype, + String? commonSubtype, }) => Parameter( type: type ?? this.type, @@ -257,8 +262,8 @@ class Parameter { isFinal: isFinal ?? this.isFinal, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, - isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? - this.isCommonWithDifferentNullability, + commonSupertype: commonSupertype ?? this.commonSupertype, + commonSubtype: commonSubtype ?? this.commonSubtype, parameterElement: parameterElement, ); @@ -295,7 +300,8 @@ class LocalParameter extends Parameter { required List decorators, required String doc, required bool isPossiblyDartCollection, - required bool isCommonWithDifferentNullability, + required String? commonSupertype, + required String? commonSubtype, required ParameterElement? parameterElement, }) : super( name: name, @@ -311,7 +317,8 @@ class LocalParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, - isCommonWithDifferentNullability: isCommonWithDifferentNullability, + commonSupertype: commonSupertype, + commonSubtype: commonSubtype, parameterElement: parameterElement, ); @@ -329,7 +336,8 @@ class LocalParameter extends Parameter { decorators: p.decorators, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, - isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, + commonSupertype: p.commonSupertype, + commonSubtype: p.commonSubtype, parameterElement: p.parameterElement, ); @@ -364,7 +372,8 @@ class CallbackParameter extends Parameter { required this.parameters, required String doc, required bool isPossiblyDartCollection, - required bool isCommonWithDifferentNullability, + required String? commonSupertype, + required String? commonSubtype, required ParameterElement? parameterElement, }) : super( name: name, @@ -380,7 +389,8 @@ class CallbackParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, - isCommonWithDifferentNullability: isCommonWithDifferentNullability, + commonSupertype: commonSupertype, + commonSubtype: commonSubtype, parameterElement: parameterElement, ); diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index 9d4f118b..c4812e3f 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -32,8 +32,8 @@ class Property { required this.isDartMap, required this.isDartSet, required this.isPossiblyDartCollection, - required this.isCommonWithDifferentNullability, - required this.parameterElement, + required this.commonSupertype, + required this.commonSubtype, }) : type = type ?? 'dynamic'; Property.fromParameter(Parameter p) @@ -51,8 +51,8 @@ class Property { isPossiblyDartCollection: p.isPossiblyDartCollection, // TODO: support hasJsonKey hasJsonKey: false, - isCommonWithDifferentNullability: p.isCommonWithDifferentNullability, - parameterElement: p.parameterElement, + commonSupertype: p.commonSupertype, + commonSubtype: p.commonSubtype, ); static Future fromParameterElement( @@ -82,8 +82,8 @@ class Property { defaultValueSource: defaultValue, hasJsonKey: element.hasJsonKey, isPossiblyDartCollection: element.type.isPossiblyDartCollection, - isCommonWithDifferentNullability: false, - parameterElement: element, + commonSupertype: null, + commonSubtype: null, ); } @@ -99,8 +99,12 @@ class Property { final bool hasJsonKey; final String doc; final bool isPossiblyDartCollection; - final bool isCommonWithDifferentNullability; - final ParameterElement? parameterElement; + final String? commonSupertype; + final String? commonSubtype; + + bool get isCopyable => + (commonSupertype != null && commonSubtype != null) || + (commonSupertype == null && commonSubtype == null); @override String toString() { @@ -110,7 +114,7 @@ class Property { Getter get unimplementedGetter => Getter( name: name, - type: type, + type: commonSupertype ?? type, decorators: decorators, doc: doc, body: ' => throw $privConstUsedErrorVarName;', @@ -134,7 +138,7 @@ class Property { Setter get unimplementedSetter => Setter( name: name, - type: type, + type: commonSubtype ?? type, decorators: decorators, doc: doc, body: ' => throw $privConstUsedErrorVarName;', @@ -161,7 +165,8 @@ class Property { bool? hasJsonKey, String? doc, bool? isPossiblyDartCollection, - bool? isCommonWithDifferentNullability, + String? commonSupertype, + String? commonSubtype, ParameterElement? parameterElement, }) { return Property( @@ -178,9 +183,8 @@ class Property { isDartSet: isDartSet ?? this.isDartSet, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, - isCommonWithDifferentNullability: isCommonWithDifferentNullability ?? - this.isCommonWithDifferentNullability, - parameterElement: parameterElement ?? this.parameterElement, + commonSupertype: commonSupertype ?? this.commonSupertype, + commonSubtype: commonSubtype ?? this.commonSubtype, ); } } diff --git a/packages/freezed/lib/src/templates/prototypes.dart b/packages/freezed/lib/src/templates/prototypes.dart index 6db70748..d7e44336 100644 --- a/packages/freezed/lib/src/templates/prototypes.dart +++ b/packages/freezed/lib/src/templates/prototypes.dart @@ -127,7 +127,8 @@ String _mapPrototype( // TODO: do we want to support freezed classes that implements MapView/ListView? isPossiblyDartCollection: false, showDefaultValue: false, - isCommonWithDifferentNullability: false, + commonSupertype: null, + commonSubtype: null, parameterElement: null, ), ]); @@ -193,7 +194,8 @@ String _unionPrototype( defaultValueSource: '', doc: '', isPossiblyDartCollection: false, - isCommonWithDifferentNullability: false, + commonSupertype: null, + commonSubtype: null, parameterElement: null, ); diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 5919bf2c..70e2773f 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -65,12 +65,30 @@ class SharedParam with _$SharedParam { } @freezed -class SharedParamCommonSuperType with _$SharedParamCommonSuperType { - const factory SharedParamCommonSuperType(String a, int b, int c) = - SharedParamCommonSuperType0; +class SharedParamCommonSuperSubtype with _$SharedParamCommonSuperSubtype { + const factory SharedParamCommonSuperSubtype(String a, int b, double c) = + SharedParamCommonSuperSubtype0; - const factory SharedParamCommonSuperType.named(String? a, double b, int d) = - SharedParamCommonSuperType1; + const factory SharedParamCommonSuperSubtype.named( + String? a, double b, num c) = SharedParamCommonSuperSubtype1; +} + +class SharedParamCommonSupertypeA {} + +class SharedParamCommonSupertypeB implements SharedParamCommonSupertypeA {} + +class SharedParamCommonSupertypeC implements SharedParamCommonSupertypeB {} + +class SharedParamCommonSupertypeD implements SharedParamCommonSupertypeA {} + +@freezed +class SharedParamCommonSupertype with _$SharedParamCommonSupertype { + const factory SharedParamCommonSupertype(SharedParamCommonSupertypeB param) = + SharedParamCommonSupertype0; + const factory SharedParamCommonSupertype.one( + SharedParamCommonSupertypeC param) = SharedParamCommonSupertype1; + const factory SharedParamCommonSupertype.two( + SharedParamCommonSupertypeD param) = SharedParamCommonSupertype2; } @freezed diff --git a/packages/freezed/test/integration/single_class_constructor.dart b/packages/freezed/test/integration/single_class_constructor.dart index f5fee495..3568c4a1 100644 --- a/packages/freezed/test/integration/single_class_constructor.dart +++ b/packages/freezed/test/integration/single_class_constructor.dart @@ -450,7 +450,7 @@ class NullDefault with _$NullDefault { class ExplicitConstDefault with _$ExplicitConstDefault { factory ExplicitConstDefault( //ignore: unnecessary_const - [@Default([]) List value]) = _ExplicitConstDefault; + [@Default(const []) List value]) = _ExplicitConstDefault; } @freezed diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index 0d5cd62f..474c5c85 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -506,35 +506,38 @@ void main() { }); }); - group('SharedParamCommonSuperType', () { + group('SharedParamCommonSuperSubtype', () { test('has the common properties available', () { - SharedParamCommonSuperType value = - SharedParamCommonSuperType('a', 1337, 42); + SharedParamCommonSuperSubtype value = + SharedParamCommonSuperSubtype('a', 1337, 42.24); expect(value.a, 'a'); expect(value.b, 1337); + expect(value.c, 42.24); - value = SharedParamCommonSuperType.named('b', 2.4, 24); + value = SharedParamCommonSuperSubtype.named('b', 12.34, 56.78); expect(value.a, 'b'); - expect(value.b, 2.4); + expect(value.b, 12.34); + expect(value.c, 56.78); }); - test('copy has different nullability available', () { - SharedParamCommonSuperType value = - SharedParamCommonSuperType('a', 1337, 42); + test('copy has all with common subtypes available', () { + SharedParamCommonSuperSubtype value = + SharedParamCommonSuperSubtype('a', 1337, 42); expect(value.a, 'a'); - value = value.copyWith(a: 'b'); + value = value.copyWith(a: 'b', c: 24.42); expect(value.a, 'b'); + expect(value.c, 24.42); }); test( - 'copy has shared params with different nullability available as non-null', + 'copy has shared params with common subtypes available', () async { await expectLater(compile(r''' import 'multiple_constructors.dart'; void main() { - final param = SharedParamCommonSuperType('a', 1337, 42); + final param = SharedParamCommonSuperSubtype('a', 1337, 42); param.copyWith(a: '2'); } '''), completes); @@ -543,28 +546,84 @@ void main() { import 'multiple_constructors.dart'; void main() { - final param = SharedParamCommonSuperType('a', 1337, 42); + final param = SharedParamCommonSuperSubtype('a', 1337, 42); + param.copyWith(c: 12.34); +} +'''), completes); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamCommonSuperSubtype('a', 1337, 42); + param.copyWith(c: 24.42); +} +'''), completes); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamCommonSuperSubtype('a', 1337, 42); param.copyWith(a: null); } +'''), throwsCompileError); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamCommonSuperSubtype('a', 1337, 42); + param.copyWith(c: null); +} '''), throwsCompileError); }, ); test( - 'copy does not have shared params with common super type available', + 'copy does not have shared params without common subtype available', () async { await expectLater(compile(r''' import 'multiple_constructors.dart'; void main() { - final param = SharedParamCommonSuperType('a', 'b', 42); + final param = SharedParamCommonSuperSubtype('a', 1337, 42); param.copyWith(b: 42); } +'''), throwsCompileError); + + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + final param = SharedParamCommonSuperSubtype('a', 1337, 42); + param.copyWith(b: null); +} '''), throwsCompileError); }, ); }); + group('SharedParamCommonSupertype', () { + test('has common param available', () { + SharedParamCommonSupertype value = + SharedParamCommonSupertype(SharedParamCommonSupertypeB()); + expect(value.param, isA()); + }); + + test('does not have copy available', () async { + await expectLater(compile(r''' +import 'multiple_constructors.dart'; + +void main() { + SharedParamCommonSupertype param = + SharedParamCommonSupertype(SharedParamCommonSupertypeB()); + param.copyWith; +} +'''), throwsCompileError); + }); + }); + test('Can have a named constructor and a property using the same name', () { var error = Error(); final value = NameConflict.error(error); From fe796dcbfa15352448ac763d1419a6dbddcc5b80 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Fri, 19 Aug 2022 01:27:41 +0200 Subject: [PATCH 06/23] fix: fixed failing some failing cases --- .../freezed/lib/src/freezed_generator.dart | 92 ++++--- .../lib/src/templates/abstract_template.dart | 4 +- .../freezed/lib/src/templates/properties.dart | 25 +- packages/freezed/lib/src/utils.dart | 13 + packages/freezed/test/common_types_test.dart | 231 ++++++++++++++++++ .../test/integration/common_types.dart | 105 ++++++++ .../integration/multiple_constructors.dart | 27 -- .../test/multiple_constructors_test.dart | 118 --------- 8 files changed, 429 insertions(+), 186 deletions(-) create mode 100644 packages/freezed/test/common_types_test.dart create mode 100644 packages/freezed/test/integration/common_types.dart diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index cab5a90f..8e198473 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -234,11 +234,23 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C ) { return constructorsNeedsGeneration.first.parameters.allParameters .map((parameter) { + final library = parameter.parameterElement!.library!; + + String typeString(DartType type, {bool withNullability = true}) { + return resolveFullTypeStringFrom( + library, + type, + withNullability: withNullability, + ); + } + var anyMatchingPropertyIsFinal = false; - var commonSupertype = parameter.parameterElement!.type; - var commonSubtype = parameter.parameterElement?.type; - final library = parameter.parameterElement!.library!; + var commonSupertypeDartType = parameter.parameterElement!.type; + var commonSubTypeDartType = parameter.parameterElement?.type; + + String? commonSupertypeString; + String? commonSubtypeString; for (final constructor in constructorsNeedsGeneration.skip(1)) { final matchingParameter = constructor.parameters.allParameters @@ -247,43 +259,57 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C if (matchingParameter == null) return null; final matchingParameterType = matchingParameter.parameterElement!.type; + if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - commonSupertype = library.typeSystem.leastUpperBound( - commonSupertype, - matchingParameterType, - ); - - if (commonSupertype - .getDisplayString(withNullability: true) - .contains('dynamic')) return null; + if (commonSupertypeDartType is FunctionType || + commonSupertypeDartType.isDynamic) { + // If the type is a typedef, by finding the upper bound we would lose + // the initial definition. Therefore FunctionTypes are currently not + // supported for finding in finding common super types. + // => Resort back to type string matching. + commonSupertypeString ??= parameter.type!; + if (commonSupertypeString.contains('dynamic')) return null; + + if (!typeStringsEqualIgnoringNullability( + commonSupertypeString, matchingParameter.type!)) { + return null; + } - if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; + if (commonSupertypeDartType.isNullable != + matchingParameterType.isNullable) { + commonSupertypeString = + typeStringWithNullability(commonSupertypeString); + commonSubtypeString = + typeStringWithoutNullability(commonSupertypeString); + } + } else { + commonSupertypeDartType = library.typeSystem.leastUpperBound( + commonSupertypeDartType, + matchingParameterType, + ); - if (commonSubtype != null) { - if (library.typeSystem - .isSubtypeOf(matchingParameterType, commonSubtype)) { - commonSubtype = matchingParameterType; - } else if (!library.typeSystem - .isSubtypeOf(commonSubtype, matchingParameterType)) { - commonSubtype = null; + if (commonSupertypeDartType + .getDisplayString(withNullability: true) + .contains('dynamic')) return null; + + if (commonSubTypeDartType != null) { + if (library.typeSystem + .isSubtypeOf(matchingParameterType, commonSubTypeDartType)) { + commonSubTypeDartType = matchingParameterType; + } else if (!library.typeSystem + .isSubtypeOf(commonSubTypeDartType, matchingParameterType)) { + commonSubTypeDartType = null; + } } } } return parameter.copyWith( isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, - commonSupertype: resolveFullTypeStringFrom( - library, - commonSupertype, - withNullability: true, - ), - commonSubtype: commonSubtype?.let( - (cs) => resolveFullTypeStringFrom( - library, - cs, - withNullability: true, - ), - ), + commonSupertype: + commonSupertypeString ?? typeString(commonSupertypeDartType), + commonSubtype: + commonSubtypeString ?? commonSubTypeDartType?.let(typeString), ); }).whereNotNull(); } @@ -851,3 +877,7 @@ extension Let on T { @pragma('vm:prefer-inline') R let(R Function(T) f) => f(this); } + +extension on DartType { + bool get isNullable => nullabilitySuffix == NullabilitySuffix.question; +} diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index ae934f77..5b276097 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -18,10 +18,12 @@ class Abstract { @override String toString() { final abstractProperties = commonProperties - .expand((e) => [ + .expand((e) => [ e.unimplementedGetter, if (!e.isFinal) e.unimplementedSetter, ]) + .whereType() + .map((e) => e.toString()) .join(); return ''' diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index c4812e3f..753d5582 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -136,13 +136,16 @@ class Property { body: body, ); - Setter get unimplementedSetter => Setter( - name: name, - type: commonSubtype ?? type, - decorators: decorators, - doc: doc, - body: ' => throw $privConstUsedErrorVarName;', - ); + Setter? get unimplementedSetter => + commonSupertype != null && commonSubtype != commonSupertype + ? null + : Setter( + name: name, + type: commonSubtype ?? type, + decorators: decorators, + doc: doc, + body: ' => throw $privConstUsedErrorVarName;', + ); Setter get abstractSetter => Setter( name: name, @@ -189,7 +192,11 @@ class Property { } } -class Getter { +class ClassMember { + const ClassMember(); +} + +class Getter implements ClassMember { Getter({ required String? type, required this.name, @@ -210,7 +217,7 @@ class Getter { } } -class Setter { +class Setter implements ClassMember { Setter({ required String? type, required this.name, diff --git a/packages/freezed/lib/src/utils.dart b/packages/freezed/lib/src/utils.dart index 39687221..1b4546a0 100644 --- a/packages/freezed/lib/src/utils.dart +++ b/packages/freezed/lib/src/utils.dart @@ -71,3 +71,16 @@ String _fixCase(String input, String separator) => return lower; }); + +String typeStringWithoutNullability(String typeString) { + return typeString.replaceAll(RegExp(r'\?$'), ''); +} + +String typeStringWithNullability(String typeString) { + return typeString.endsWith('?') ? typeString : '$typeString?'; +} + +bool typeStringsEqualIgnoringNullability(String typeA, String typeB) { + return typeStringWithoutNullability(typeA) == + typeStringWithoutNullability(typeB); +} diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart new file mode 100644 index 00000000..f52d8bfe --- /dev/null +++ b/packages/freezed/test/common_types_test.dart @@ -0,0 +1,231 @@ +// ignore_for_file: prefer_const_constructors, omit_local_variable_types, deprecated_member_use_from_same_package, cascade_invocations +import 'package:analyzer/dart/analysis/results.dart'; +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:build_test/build_test.dart'; +import 'package:test/test.dart'; + +import 'common.dart'; +import 'integration/common_types.dart'; + +void main() { + test('has no issue', () async { + final main = await resolveSources( + { + 'freezed|test/integration/common_types.dart': useAssetReader, + }, + (r) => r.libraries.firstWhere( + (element) => element.source.toString().contains('common_types')), + ); + + final errorResult = await main.session + .getErrors('/freezed/test/integration/common_types.freezed.dart') + as ErrorsResult; + + expect(errorResult.errors, isEmpty); + }); + + group('CommonSuperSubtype', () { + test('has the common properties available', () { + var value = CommonSuperSubtype('a', 1337, 42.24); + expect(value.a, 'a'); + expect(value.b, 1337); + expect(value.c, 42.24); + + value = CommonSuperSubtype.named('b', 12.34, 56.78); + expect(value.a, 'b'); + expect(value.b, 12.34); + expect(value.c, 56.78); + }); + + test('copy has all with common subtypes available', () { + var value = CommonSuperSubtype('a', 1337, 42); + expect(value.a, 'a'); + + value = value.copyWith(a: 'b', c: 24.42); + expect(value.a, 'b'); + expect(value.c, 24.42); + }); + + test( + 'copy has shared params with common subtypes available', + () async { + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(a: '2'); +} +'''), completes); + + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(c: 12.34); +} +'''), completes); + + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(c: 24.42); +} +'''), completes); + + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(a: null); +} +'''), throwsCompileError); + + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(c: null); +} +'''), throwsCompileError); + }, + ); + + test( + 'copy does not have shared params without common subtype available', + () async { + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(b: 42); +} +'''), throwsCompileError); + + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonSuperSubtype('a', 1337, 42); + param.copyWith(b: null); +} +'''), throwsCompileError); + }, + ); + }); + + group('GeneratedDependency', () { + test('should have getters available', () async { + final param = GeneratedDependency(Dependency0()); + expect(param.a, isA()); + }); + }); + + group('CommonInterfaceSupertype', () { + test('has common param available', () { + var value = CommonInterfaceSupertype(CommonInterfaceB()); + expect(value.param, isA()); + }); + + test('does not have copy available', () async { + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + CommonInterfaceSupertype param = + CommonInterfaceSupertype(CommonInterfaceB()); + param.copyWith; +} +'''), throwsCompileError); + }); + }); + + group('CommonTypedefs', () { + test('generates correct typedefs', () async { + final main = await resolveSources( + { + 'freezed|test/integration/common_types.dart': useAssetReader, + }, + (r) => r.libraries.firstWhere( + (element) => element.source.toString().contains('common_types')), + ); + + var freezedClass = main.topLevelElements + .whereType() + .firstWhere((element) => element.displayName == r'_$CommonTypedefs'); + + var a = freezedClass.getGetter('a')!.returnType; + expect(a, isA()); + expect(a.alias!.element.name, equals('ExternalTypedef')); + + var b = freezedClass.getGetter('b')!.returnType; + expect(b, isA()); + expect(b.alias!.element.name, equals('ExternalTypedefTwo')); + + var c = freezedClass.getGetter('c')!.returnType; + expect(c, isA()); + expect(c.element2!.name, equals('String')); + + var e = freezedClass.getGetter('genericTypedef')!.returnType; + expect(e, isA()); + expect(e.alias!.element.name, equals('GenericTypedef')); + expect(e.alias!.typeArguments.toString(), equals('[int, bool]')); + }); + }); + + group('CommonTypeNestedContainer', () { + test( + 'nested copyWith with a default value that is not a subtype of the common subtype', + () { + var commonTypeContainer = CommonTypeNestedContainer( + internal: CommonTypeNested.two(a: 0.0), + ); + commonTypeContainer = commonTypeContainer.copyWith.internal(); + expect(commonTypeContainer.internal.a, 0.0); + + commonTypeContainer = commonTypeContainer.copyWith.internal(a: 12); + expect(commonTypeContainer.internal.a, 12); + }, + ); + }); + + group('CommonUnfreezed', () { + test('should have common getters available', () { + var value = CommonUnfreezed.one(a: 42, b: 3.14); + expect(value.a, 42); + expect(value.b, 3.14); + }); + + test('should have common setters available', () { + var value = CommonUnfreezed.one(a: 42, b: 3.14); + value.b = 42.24; + expect(value.b, 42.24); + }); + + test('should not have setters for getters with different type', () async { + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonUnfreezed.one(a: 42, b: 3.14); + param.a = 42.24; +} +'''), throwsCompileError); + await expectLater(compile(r''' +import 'common_types.dart'; + +void main() { + final param = CommonUnfreezed.one(a: 42, b: 3.14); + param.b = 42.24; +} +'''), completes); + }); + }); +} diff --git a/packages/freezed/test/integration/common_types.dart b/packages/freezed/test/integration/common_types.dart new file mode 100644 index 00000000..68781df8 --- /dev/null +++ b/packages/freezed/test/integration/common_types.dart @@ -0,0 +1,105 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'external_typedef.dart'; +import 'external_typedef_two.dart' as two; +import 'typedef_parameter.dart'; + +part 'common_types.freezed.dart'; + +@freezed +class Dependency with _$Dependency { + const factory Dependency() = Dependency0; +} + +@freezed +class GeneratedDependency with _$GeneratedDependency { + const factory GeneratedDependency(Dependency0 a) = _GeneratedDependency0; + + const factory GeneratedDependency.named({required Dependency0 a}) = + _GeneratedDependency1; +} + +@freezed +class CommonSuperSubtype with _$CommonSuperSubtype { + const factory CommonSuperSubtype( + String a, + int b, + double c, + ) = CommonSuperSubtype0; + + const factory CommonSuperSubtype.named( + String? a, + double b, + num c, + ) = CommonSuperSubtype1; +} + +class CommonInterface { + const CommonInterface(); +} + +class CommonInterfaceA implements CommonInterface { + const CommonInterfaceA(); +} + +class CommonInterfaceB implements CommonInterfaceA { + const CommonInterfaceB(); +} + +class CommonInterfaceC implements CommonInterface { + const CommonInterfaceC(); +} + +@freezed +class CommonInterfaceSupertype with _$CommonInterfaceSupertype { + const factory CommonInterfaceSupertype( + CommonInterfaceA param, + ) = CommonInterfaceSupertype0; + + const factory CommonInterfaceSupertype.one( + CommonInterfaceB param, + ) = CommonInterfaceSupertype1; + + const factory CommonInterfaceSupertype.two( + CommonInterfaceC param, + ) = CommonInterfaceSupertype2; +} + +typedef TypedefString = String; + +@freezed +class CommonTypedefs with _$CommonTypedefs { + const factory CommonTypedefs.one({ + required ExternalTypedef a, + required two.ExternalTypedefTwo b, + required TypedefString c, + required GenericTypedef genericTypedef, + }) = CommonTypedefsOne; + + const factory CommonTypedefs.two({ + required ExternalTypedef? a, + required two.ExternalTypedefTwo? b, + required TypedefString? c, + required GenericTypedef genericTypedef, + }) = CommonTypedefsTwo; +} + +@freezed +class CommonTypeNested with _$CommonTypeNested { + const factory CommonTypeNested.one({required int a}) = CommonTypeNestedOne; + const factory CommonTypeNested.two({required num a}) = CommonTypeNestedTwo; +} + +@freezed +class CommonTypeNestedContainer with _$CommonTypeNestedContainer { + const factory CommonTypeNestedContainer({ + required CommonTypeNested internal, + }) = _CommonTypeNestedContainer; +} + +@unfreezed +class CommonUnfreezed with _$CommonUnfreezed { + factory CommonUnfreezed.one({required int a, required double b}) = + CommonUnfreezedOne; + factory CommonUnfreezed.two({required num a, required double b}) = + CommonUnfreezedTwo; +} diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 70e2773f..62b8b671 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -64,33 +64,6 @@ class SharedParam with _$SharedParam { const factory SharedParam.named(String a, int c) = SharedParam1; } -@freezed -class SharedParamCommonSuperSubtype with _$SharedParamCommonSuperSubtype { - const factory SharedParamCommonSuperSubtype(String a, int b, double c) = - SharedParamCommonSuperSubtype0; - - const factory SharedParamCommonSuperSubtype.named( - String? a, double b, num c) = SharedParamCommonSuperSubtype1; -} - -class SharedParamCommonSupertypeA {} - -class SharedParamCommonSupertypeB implements SharedParamCommonSupertypeA {} - -class SharedParamCommonSupertypeC implements SharedParamCommonSupertypeB {} - -class SharedParamCommonSupertypeD implements SharedParamCommonSupertypeA {} - -@freezed -class SharedParamCommonSupertype with _$SharedParamCommonSupertype { - const factory SharedParamCommonSupertype(SharedParamCommonSupertypeB param) = - SharedParamCommonSupertype0; - const factory SharedParamCommonSupertype.one( - SharedParamCommonSupertypeC param) = SharedParamCommonSupertype1; - const factory SharedParamCommonSupertype.two( - SharedParamCommonSupertypeD param) = SharedParamCommonSupertype2; -} - @freezed class Complex with _$Complex { @Assert("a != ''", '"Hello"') diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index 474c5c85..de5f06bb 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -506,124 +506,6 @@ void main() { }); }); - group('SharedParamCommonSuperSubtype', () { - test('has the common properties available', () { - SharedParamCommonSuperSubtype value = - SharedParamCommonSuperSubtype('a', 1337, 42.24); - expect(value.a, 'a'); - expect(value.b, 1337); - expect(value.c, 42.24); - - value = SharedParamCommonSuperSubtype.named('b', 12.34, 56.78); - expect(value.a, 'b'); - expect(value.b, 12.34); - expect(value.c, 56.78); - }); - - test('copy has all with common subtypes available', () { - SharedParamCommonSuperSubtype value = - SharedParamCommonSuperSubtype('a', 1337, 42); - expect(value.a, 'a'); - - value = value.copyWith(a: 'b', c: 24.42); - expect(value.a, 'b'); - expect(value.c, 24.42); - }); - - test( - 'copy has shared params with common subtypes available', - () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(a: '2'); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(c: 12.34); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(c: 24.42); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(a: null); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(c: null); -} -'''), throwsCompileError); - }, - ); - - test( - 'copy does not have shared params without common subtype available', - () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(b: 42); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final param = SharedParamCommonSuperSubtype('a', 1337, 42); - param.copyWith(b: null); -} -'''), throwsCompileError); - }, - ); - }); - - group('SharedParamCommonSupertype', () { - test('has common param available', () { - SharedParamCommonSupertype value = - SharedParamCommonSupertype(SharedParamCommonSupertypeB()); - expect(value.param, isA()); - }); - - test('does not have copy available', () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - SharedParamCommonSupertype param = - SharedParamCommonSupertype(SharedParamCommonSupertypeB()); - param.copyWith; -} -'''), throwsCompileError); - }); - }); - test('Can have a named constructor and a property using the same name', () { var error = Error(); final value = NameConflict.error(error); From f4f778095f044d00f68cda82091bac9805254d0a Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Sat, 20 Aug 2022 23:21:04 +0200 Subject: [PATCH 07/23] refactor: address pr comments --- .../freezed/lib/src/freezed_generator.dart | 157 +++++++------- .../lib/src/templates/abstract_template.dart | 17 +- .../freezed/lib/src/templates/copy_with.dart | 46 ++--- .../freezed/lib/src/templates/properties.dart | 21 +- packages/freezed/pubspec.yaml | 1 + packages/freezed/test/common_types_test.dart | 192 ++++++------------ 6 files changed, 191 insertions(+), 243 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 8e198473..1ffc1944 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -229,89 +229,92 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return false; } - Iterable _commonPropertiesBetweenAllConstructors( + List _commonPropertiesBetweenAllConstructors( List constructorsNeedsGeneration, ) { return constructorsNeedsGeneration.first.parameters.allParameters .map((parameter) { - final library = parameter.parameterElement!.library!; - - String typeString(DartType type, {bool withNullability = true}) { - return resolveFullTypeStringFrom( - library, - type, - withNullability: withNullability, - ); - } - - var anyMatchingPropertyIsFinal = false; - - var commonSupertypeDartType = parameter.parameterElement!.type; - var commonSubTypeDartType = parameter.parameterElement?.type; - - String? commonSupertypeString; - String? commonSubtypeString; - - for (final constructor in constructorsNeedsGeneration.skip(1)) { - final matchingParameter = constructor.parameters.allParameters - .firstWhereOrNull((p) => p.name == parameter.name); - - if (matchingParameter == null) return null; - - final matchingParameterType = matchingParameter.parameterElement!.type; - if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - - if (commonSupertypeDartType is FunctionType || - commonSupertypeDartType.isDynamic) { - // If the type is a typedef, by finding the upper bound we would lose - // the initial definition. Therefore FunctionTypes are currently not - // supported for finding in finding common super types. - // => Resort back to type string matching. - commonSupertypeString ??= parameter.type!; - if (commonSupertypeString.contains('dynamic')) return null; - - if (!typeStringsEqualIgnoringNullability( - commonSupertypeString, matchingParameter.type!)) { - return null; + final library = parameter.parameterElement!.library!; + + String typeString(DartType type, {bool withNullability = true}) { + return resolveFullTypeStringFrom( + library, + type, + withNullability: withNullability, + ); } - if (commonSupertypeDartType.isNullable != - matchingParameterType.isNullable) { - commonSupertypeString = - typeStringWithNullability(commonSupertypeString); - commonSubtypeString = - typeStringWithoutNullability(commonSupertypeString); - } - } else { - commonSupertypeDartType = library.typeSystem.leastUpperBound( - commonSupertypeDartType, - matchingParameterType, - ); - - if (commonSupertypeDartType - .getDisplayString(withNullability: true) - .contains('dynamic')) return null; - - if (commonSubTypeDartType != null) { - if (library.typeSystem - .isSubtypeOf(matchingParameterType, commonSubTypeDartType)) { - commonSubTypeDartType = matchingParameterType; - } else if (!library.typeSystem - .isSubtypeOf(commonSubTypeDartType, matchingParameterType)) { - commonSubTypeDartType = null; + var anyMatchingPropertyIsFinal = false; + + var commonSupertypeDartType = parameter.parameterElement!.type; + var commonSubTypeDartType = parameter.parameterElement?.type; + + String? commonSupertypeString; + String? commonSubtypeString; + + for (final constructor in constructorsNeedsGeneration.skip(1)) { + final matchingParameter = constructor.parameters.allParameters + .firstWhereOrNull((p) => p.name == parameter.name); + + if (matchingParameter == null) return null; + + final matchingParameterType = + matchingParameter.parameterElement!.type; + if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; + + if (commonSupertypeDartType is FunctionType || + commonSupertypeDartType.isDynamic) { + // If the type is a typedef, by finding the upper bound we would lose + // the initial definition. Therefore FunctionTypes are currently not + // supported for finding in finding common super types. + // => Resort back to type string matching. + commonSupertypeString ??= parameter.type!; + if (commonSupertypeString.contains('dynamic')) return null; + + if (!typeStringsEqualIgnoringNullability( + commonSupertypeString, matchingParameter.type!)) { + return null; + } + + if (commonSupertypeDartType.isNullable != + matchingParameterType.isNullable) { + commonSupertypeString = + typeStringWithNullability(commonSupertypeString); + commonSubtypeString = + typeStringWithoutNullability(commonSupertypeString); + } + } else { + commonSupertypeDartType = library.typeSystem.leastUpperBound( + commonSupertypeDartType, + matchingParameterType, + ); + + if (commonSupertypeDartType + .getDisplayString(withNullability: true) + .contains('dynamic')) return null; + + if (commonSubTypeDartType != null) { + if (library.typeSystem.isSubtypeOf( + matchingParameterType, commonSubTypeDartType)) { + commonSubTypeDartType = matchingParameterType; + } else if (!library.typeSystem.isSubtypeOf( + commonSubTypeDartType, matchingParameterType)) { + commonSubTypeDartType = null; + } + } } } - } - } - return parameter.copyWith( - isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, - commonSupertype: - commonSupertypeString ?? typeString(commonSupertypeDartType), - commonSubtype: - commonSubtypeString ?? commonSubTypeDartType?.let(typeString), - ); - }).whereNotNull(); + return parameter.copyWith( + isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, + commonSupertype: + commonSupertypeString ?? typeString(commonSupertypeDartType), + commonSubtype: + commonSubtypeString ?? commonSubTypeDartType?.let(typeString), + ); + }) + .whereNotNull() + .toList(); } Future> _parseConstructorsNeedsGeneration( @@ -479,8 +482,8 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } Iterable _commonCloneableProperties( - Iterable constructors, - Iterable commonProperties, + List constructors, + List commonProperties, ) sync* { for (final cloneableProperty in constructors.first.cloneableProperties) { for (final commonProperty in commonProperties) { @@ -637,7 +640,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C final commonProperties = _commonProperties(data.constructors); final commonCopyableProperties = - commonProperties.where((p) => p.isCopyable); + commonProperties.where((p) => p.isCopyable).toList(); final commonCopyWith = !data.generateCopyWith ? null diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 5b276097..a2f7c780 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -13,15 +13,22 @@ class Abstract { final Data data; final CopyWith? copyWith; - final Iterable commonProperties; + final List commonProperties; @override String toString() { final abstractProperties = commonProperties - .expand((e) => [ - e.unimplementedGetter, - if (!e.isFinal) e.unimplementedSetter, - ]) + .expand((e) { + return [ + e.unimplementedGetter, + if (!e.isFinal && + // Don't add a setter for a field where the setters type is not + // a subtype of the getters type. + !(e.commonSupertype != null && + e.commonSubtype != e.commonSupertype)) + e.unimplementedSetter, + ]; + }) .whereType() .map((e) => e.toString()) .join(); diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index 478f6af8..083ef2e2 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -24,7 +24,7 @@ class CopyWith { final String clonedClassName; final GenericsDefinitionTemplate genericsDefinition; final GenericsParameterTemplate genericsParameter; - final Iterable allProperties; + final List allProperties; final List cloneableProperties; final CopyWith? parent; final Data data; @@ -63,26 +63,26 @@ ${_abstractDeepCopyMethods().join()} final body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: allProperties - .map((e) => Parameter( - decorators: e.decorators, - name: e.name, - isNullable: false, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - showDefaultValue: false, - isRequired: false, - defaultValueSource: '', - type: e.commonSupertype ?? e.type, - doc: e.doc, - isPossiblyDartCollection: e.isPossiblyDartCollection, - commonSupertype: e.commonSupertype, - commonSubtype: e.commonSubtype, - parameterElement: null, - )) - .toList(), + namedParameters: allProperties.map((e) { + return Parameter( + decorators: e.decorators, + name: e.name, + isNullable: false, + isFinal: false, + isDartList: false, + isDartMap: false, + isDartSet: false, + showDefaultValue: false, + isRequired: false, + defaultValueSource: '', + type: e.commonSupertype ?? e.type, + doc: e.doc, + isPossiblyDartCollection: e.isPossiblyDartCollection, + commonSupertype: e.commonSupertype, + commonSubtype: e.commonSubtype, + parameterElement: null, + ); + }).toList(), ), returnType: '_value.copyWith', ); @@ -131,7 +131,7 @@ ${_deepCopyMethods().join()} String _copyWithProtypeFor({ required String methodName, - required Iterable properties, + required List properties, }) { final parameters = properties.map((p) { final type = p.commonSubtype ?? p.type; @@ -236,7 +236,7 @@ $constructorParameters } String _concreteCopyWithPrototype({ - required Iterable properties, + required List properties, required String methodName, }) { final parameters = properties.map((p) { diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index 753d5582..31e2d37a 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -102,9 +102,7 @@ class Property { final String? commonSupertype; final String? commonSubtype; - bool get isCopyable => - (commonSupertype != null && commonSubtype != null) || - (commonSupertype == null && commonSubtype == null); + bool get isCopyable => commonSupertype == commonSubtype; @override String toString() { @@ -136,16 +134,13 @@ class Property { body: body, ); - Setter? get unimplementedSetter => - commonSupertype != null && commonSubtype != commonSupertype - ? null - : Setter( - name: name, - type: commonSubtype ?? type, - decorators: decorators, - doc: doc, - body: ' => throw $privConstUsedErrorVarName;', - ); + Setter get unimplementedSetter => Setter( + name: name, + type: commonSubtype ?? type, + decorators: decorators, + doc: doc, + body: ' => throw $privConstUsedErrorVarName;', + ); Setter get abstractSetter => Setter( name: name, diff --git a/packages/freezed/pubspec.yaml b/packages/freezed/pubspec.yaml index f008b389..4a1e9311 100644 --- a/packages/freezed/pubspec.yaml +++ b/packages/freezed/pubspec.yaml @@ -25,3 +25,4 @@ dev_dependencies: test: ^1.20.1 matcher: ^0.12.11 source_gen_test: ^1.0.2 + expect_error: ^1.0.2 diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index f52d8bfe..68d5b2e0 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -1,14 +1,16 @@ -// ignore_for_file: prefer_const_constructors, omit_local_variable_types, deprecated_member_use_from_same_package, cascade_invocations import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:build_test/build_test.dart'; +import 'package:expect_error/expect_error.dart'; import 'package:test/test.dart'; -import 'common.dart'; import 'integration/common_types.dart'; -void main() { +// TODO: Uncomment tests when copyWith for common subtypes is implemented +Future main() async { + final library = await Library.parseFromStacktrace(); + test('has no issue', () async { final main = await resolveSources( { @@ -27,123 +29,71 @@ void main() { group('CommonSuperSubtype', () { test('has the common properties available', () { - var value = CommonSuperSubtype('a', 1337, 42.24); + var value = const CommonSuperSubtype('a', 1337, 42.24); expect(value.a, 'a'); expect(value.b, 1337); expect(value.c, 42.24); - value = CommonSuperSubtype.named('b', 12.34, 56.78); + value = const CommonSuperSubtype.named('b', 12.34, 56.78); expect(value.a, 'b'); expect(value.b, 12.34); expect(value.c, 56.78); }); - test('copy has all with common subtypes available', () { - var value = CommonSuperSubtype('a', 1337, 42); - expect(value.a, 'a'); - - value = value.copyWith(a: 'b', c: 24.42); - expect(value.a, 'b'); - expect(value.c, 24.42); - }); - - test( - 'copy has shared params with common subtypes available', - () async { - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(a: '2'); -} -'''), completes); - - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(c: 12.34); -} -'''), completes); - - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(c: 24.42); -} -'''), completes); - - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(a: null); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(c: null); -} -'''), throwsCompileError); - }, - ); - - test( - 'copy does not have shared params without common subtype available', - () async { - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(b: 42); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonSuperSubtype('a', 1337, 42); - param.copyWith(b: null); -} -'''), throwsCompileError); - }, - ); + // test('copy has all with common subtypes available', () { + // var value = const CommonSuperSubtype('a', 1337, 42); + // expect(value.a, 'a'); + + // value = value.copyWith(a: 'b', c: 24.42); + // expect(value.a, 'b'); + // expect(value.c, 24.42); + // }); + + // test('copy has shared params with common subtypes available', () async { + // var param = const CommonSuperSubtype('a', 1337, 42); + // param = param.copyWith(a: '2', c: 24.42); + // expect(param.a, '2'); + // expect(param.c, 24.42); + // }); + +// test('copy does not have shared params without common subtype available', +// () async { +// await expectLater(library.withCode(''' +// import 'integration/common_types.dart'; + +// void main() { +// final param = CommonSuperSubtype('a', 1337, 42); + +// // expect-error: UNDEFINED_NAMED_PARAMETER +// param.copyWith(b: 42); +// } +// '''), compiles); +// }); }); group('GeneratedDependency', () { test('should have getters available', () async { - final param = GeneratedDependency(Dependency0()); + final param = const GeneratedDependency(Dependency0()); expect(param.a, isA()); }); }); group('CommonInterfaceSupertype', () { test('has common param available', () { - var value = CommonInterfaceSupertype(CommonInterfaceB()); + var value = const CommonInterfaceSupertype(CommonInterfaceB()); expect(value.param, isA()); }); test('does not have copy available', () async { - await expectLater(compile(r''' -import 'common_types.dart'; + await expectLater(library.withCode(''' +import 'integration/common_types.dart'; void main() { - CommonInterfaceSupertype param = - CommonInterfaceSupertype(CommonInterfaceB()); - param.copyWith; + CommonInterfaceSupertype param = CommonInterfaceSupertype(CommonInterfaceB()); + // expect-error: UNDEFINED_METHOD + param.copyWith(); } -'''), throwsCompileError); +'''), compiles); }); }); @@ -180,21 +130,21 @@ void main() { }); }); - group('CommonTypeNestedContainer', () { - test( - 'nested copyWith with a default value that is not a subtype of the common subtype', - () { - var commonTypeContainer = CommonTypeNestedContainer( - internal: CommonTypeNested.two(a: 0.0), - ); - commonTypeContainer = commonTypeContainer.copyWith.internal(); - expect(commonTypeContainer.internal.a, 0.0); - - commonTypeContainer = commonTypeContainer.copyWith.internal(a: 12); - expect(commonTypeContainer.internal.a, 12); - }, - ); - }); + // group('CommonTypeNestedContainer', () { + // test( + // 'nested copyWith with a default value that is not a subtype of the common subtype', + // () { + // var commonTypeContainer = const CommonTypeNestedContainer( + // internal: CommonTypeNested.two(a: 0.0), + // ); + // commonTypeContainer = commonTypeContainer.copyWith.internal(); + // expect(commonTypeContainer.internal.a, 0.0); + + // commonTypeContainer = commonTypeContainer.copyWith.internal(a: 12); + // expect(commonTypeContainer.internal.a, 12); + // }, + // ); + // }); group('CommonUnfreezed', () { test('should have common getters available', () { @@ -203,29 +153,21 @@ void main() { expect(value.b, 3.14); }); - test('should have common setters available', () { - var value = CommonUnfreezed.one(a: 42, b: 3.14); - value.b = 42.24; - expect(value.b, 42.24); - }); + // test('should have common setters available', () { + // var value = CommonUnfreezed.one(a: 42, b: 3.14)..b = 42.24; + // expect(value.b, 42.24); + // }); test('should not have setters for getters with different type', () async { - await expectLater(compile(r''' -import 'common_types.dart'; + await expectLater(library.withCode(''' +import 'integration/common_types.dart'; void main() { final param = CommonUnfreezed.one(a: 42, b: 3.14); + // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER param.a = 42.24; } -'''), throwsCompileError); - await expectLater(compile(r''' -import 'common_types.dart'; - -void main() { - final param = CommonUnfreezed.one(a: 42, b: 3.14); - param.b = 42.24; -} -'''), completes); +'''), compiles); }); }); } From 5fc858ce88456b9d0ce8a60d7c543bf731bfaba1 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 27 Sep 2022 15:15:09 +0200 Subject: [PATCH 08/23] Remove dead code --- packages/freezed/test/common_types_test.dart | 30 -------------------- 1 file changed, 30 deletions(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index 68d5b2e0..790df32a 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -7,7 +7,6 @@ import 'package:test/test.dart'; import 'integration/common_types.dart'; -// TODO: Uncomment tests when copyWith for common subtypes is implemented Future main() async { final library = await Library.parseFromStacktrace(); @@ -40,35 +39,6 @@ Future main() async { expect(value.c, 56.78); }); - // test('copy has all with common subtypes available', () { - // var value = const CommonSuperSubtype('a', 1337, 42); - // expect(value.a, 'a'); - - // value = value.copyWith(a: 'b', c: 24.42); - // expect(value.a, 'b'); - // expect(value.c, 24.42); - // }); - - // test('copy has shared params with common subtypes available', () async { - // var param = const CommonSuperSubtype('a', 1337, 42); - // param = param.copyWith(a: '2', c: 24.42); - // expect(param.a, '2'); - // expect(param.c, 24.42); - // }); - -// test('copy does not have shared params without common subtype available', -// () async { -// await expectLater(library.withCode(''' -// import 'integration/common_types.dart'; - -// void main() { -// final param = CommonSuperSubtype('a', 1337, 42); - -// // expect-error: UNDEFINED_NAMED_PARAMETER -// param.copyWith(b: 42); -// } -// '''), compiles); -// }); }); group('GeneratedDependency', () { From 5ea73b9b788b3324f108395a814d5221bd681980 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 27 Sep 2022 15:16:30 +0200 Subject: [PATCH 09/23] Remove more dead code --- packages/freezed/test/common_types_test.dart | 21 -------------------- 1 file changed, 21 deletions(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index 790df32a..8c49b273 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -100,22 +100,6 @@ void main() { }); }); - // group('CommonTypeNestedContainer', () { - // test( - // 'nested copyWith with a default value that is not a subtype of the common subtype', - // () { - // var commonTypeContainer = const CommonTypeNestedContainer( - // internal: CommonTypeNested.two(a: 0.0), - // ); - // commonTypeContainer = commonTypeContainer.copyWith.internal(); - // expect(commonTypeContainer.internal.a, 0.0); - - // commonTypeContainer = commonTypeContainer.copyWith.internal(a: 12); - // expect(commonTypeContainer.internal.a, 12); - // }, - // ); - // }); - group('CommonUnfreezed', () { test('should have common getters available', () { var value = CommonUnfreezed.one(a: 42, b: 3.14); @@ -123,11 +107,6 @@ void main() { expect(value.b, 3.14); }); - // test('should have common setters available', () { - // var value = CommonUnfreezed.one(a: 42, b: 3.14)..b = 42.24; - // expect(value.b, 42.24); - // }); - test('should not have setters for getters with different type', () async { await expectLater(library.withCode(''' import 'integration/common_types.dart'; From db001c0dc50ff529ae4fbfc091af21d8a7f18b0e Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Wed, 28 Sep 2022 09:49:51 +0200 Subject: [PATCH 10/23] check for correct getter types in tests --- packages/freezed/test/common_types_test.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index 8c49b273..f44b0194 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -30,15 +30,17 @@ Future main() async { test('has the common properties available', () { var value = const CommonSuperSubtype('a', 1337, 42.24); expect(value.a, 'a'); + expect(value.a, isA()); expect(value.b, 1337); + expect(value.b, isA()); expect(value.c, 42.24); + expect(value.c, isA()); value = const CommonSuperSubtype.named('b', 12.34, 56.78); expect(value.a, 'b'); expect(value.b, 12.34); expect(value.c, 56.78); }); - }); group('GeneratedDependency', () { @@ -104,7 +106,9 @@ void main() { test('should have common getters available', () { var value = CommonUnfreezed.one(a: 42, b: 3.14); expect(value.a, 42); + expect(value.a, isA()); expect(value.b, 3.14); + expect(value.b, isA()); }); test('should not have setters for getters with different type', () async { From 98d294b29d10c99f658d5cababd771a51497d03e Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Wed, 28 Sep 2022 10:07:48 +0200 Subject: [PATCH 11/23] fix test for analyzer 5 --- packages/freezed/test/common_types_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index f44b0194..49173359 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -80,7 +80,7 @@ void main() { ); var freezedClass = main.topLevelElements - .whereType() + .whereType() .firstWhere((element) => element.displayName == r'_$CommonTypedefs'); var a = freezedClass.getGetter('a')!.returnType; From 0ea877ab5263eb9e89ca47180a3ea0ec53b60501 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Wed, 28 Sep 2022 10:19:14 +0200 Subject: [PATCH 12/23] small refactor --- .../freezed/lib/src/freezed_generator.dart | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 98a332d3..54a5f8d7 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -246,9 +246,11 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C var anyMatchingPropertyIsFinal = false; - var commonSupertypeDartType = parameter.parameterElement!.type; - var commonSubTypeDartType = parameter.parameterElement?.type; + var commonSupertype = parameter.parameterElement!.type; + var commonSubtype = parameter.parameterElement?.type; + // Required fallback type for when common types can't be resolved + // using the type system String? commonSupertypeString; String? commonSubtypeString; @@ -262,12 +264,11 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C matchingParameter.parameterElement!.type; if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - if (commonSupertypeDartType is FunctionType || - commonSupertypeDartType.isDynamic) { + if (commonSupertype is FunctionType || commonSupertype.isDynamic) { // If the type is a typedef, by finding the upper bound we would lose // the initial definition. Therefore FunctionTypes are currently not - // supported for finding in finding common super types. - // => Resort back to type string matching. + // supported as common super types. + // => Fall back to type string matching. commonSupertypeString ??= parameter.type!; if (commonSupertypeString.contains('dynamic')) return null; @@ -276,7 +277,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return null; } - if (commonSupertypeDartType.isNullable != + if (commonSupertype.isNullable != matchingParameterType.isNullable) { commonSupertypeString = typeStringWithNullability(commonSupertypeString); @@ -284,22 +285,22 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C typeStringWithoutNullability(commonSupertypeString); } } else { - commonSupertypeDartType = library.typeSystem.leastUpperBound( - commonSupertypeDartType, + commonSupertype = library.typeSystem.leastUpperBound( + commonSupertype, matchingParameterType, ); - if (commonSupertypeDartType + if (commonSupertype .getDisplayString(withNullability: true) .contains('dynamic')) return null; - if (commonSubTypeDartType != null) { - if (library.typeSystem.isSubtypeOf( - matchingParameterType, commonSubTypeDartType)) { - commonSubTypeDartType = matchingParameterType; - } else if (!library.typeSystem.isSubtypeOf( - commonSubTypeDartType, matchingParameterType)) { - commonSubTypeDartType = null; + if (commonSubtype != null) { + if (library.typeSystem + .isSubtypeOf(matchingParameterType, commonSubtype)) { + commonSubtype = matchingParameterType; + } else if (!library.typeSystem + .isSubtypeOf(commonSubtype, matchingParameterType)) { + commonSubtype = null; } } } @@ -308,9 +309,9 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return parameter.copyWith( isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, commonSupertype: - commonSupertypeString ?? typeString(commonSupertypeDartType), + commonSupertypeString ?? typeString(commonSupertype), commonSubtype: - commonSubtypeString ?? commonSubTypeDartType?.let(typeString), + commonSubtypeString ?? commonSubtype?.let(typeString), ); }) .whereNotNull() From d52f6cbb0deab28454419939582605d1b5eb5043 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 2 Oct 2022 00:10:06 +0000 Subject: [PATCH 13/23] chore: update sponsors.svg --- sponsorkit/sponsors.svg | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/sponsorkit/sponsors.svg b/sponsorkit/sponsors.svg index bc7c405a..b59bca1f 100644 --- a/sponsorkit/sponsors.svg +++ b/sponsorkit/sponsors.svg @@ -170,42 +170,46 @@ text { - + - + - + - + - + - + - + - + - + - + + + + + From 230e5865a5e4bc401573eb6a14a8547e5a0c1207 Mon Sep 17 00:00:00 2001 From: David Wimmer Date: Thu, 6 Oct 2022 18:38:21 +0200 Subject: [PATCH 14/23] Test pub downgrade via matrix (#776) --- .github/workflows/build.yml | 14 ++++++++++++-- packages/freezed/example/pubspec.yaml | 6 +++--- packages/freezed/pubspec.yaml | 19 +++++++++---------- packages/freezed/pubspec_overrides.yaml | 4 ++++ packages/freezed_annotation/pubspec.yaml | 14 ++++++++++---- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ebabaa2e..7df7daf8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,13 @@ jobs: # - packages/freezed/example channel: - master + - stable + dependencies: + - get + - downgrade + exclude: + - channel: master + dependencies: downgrade steps: - uses: actions/checkout@v2 @@ -27,16 +34,19 @@ jobs: with: channel: ${{ matrix.channel }} - # It is executed separatly + # It is executed separately - name: Removing example folder run: rm -rf example working-directory: ${{ matrix.package }} - name: Install dependencies - run: flutter pub get + run: | + flutter pub ${{ matrix.dependencies }} working-directory: ${{ matrix.package }} - name: Check format + # Check format only on master + if: matrix.channel == 'master' run: flutter format --set-exit-if-changed . working-directory: ${{ matrix.package }} diff --git a/packages/freezed/example/pubspec.yaml b/packages/freezed/example/pubspec.yaml index 61189cc8..2489c8e9 100644 --- a/packages/freezed/example/pubspec.yaml +++ b/packages/freezed/example/pubspec.yaml @@ -2,19 +2,19 @@ name: example description: A new Flutter project. environment: - sdk: ">=2.14.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" dependencies: flutter: sdk: flutter freezed_annotation: path: ../../freezed_annotation - json_annotation: ^4.4.0 + json_annotation: ^4.6.0 dev_dependencies: freezed: path: ../ - json_serializable: ^6.1.3 + json_serializable: ^6.3.2 build_runner: flutter_test: sdk: flutter diff --git a/packages/freezed/pubspec.yaml b/packages/freezed/pubspec.yaml index b0d46580..ff5fbf8a 100644 --- a/packages/freezed/pubspec.yaml +++ b/packages/freezed/pubspec.yaml @@ -10,20 +10,19 @@ environment: sdk: ">=2.17.0 <3.0.0" dependencies: - analyzer: ^5.0.0 - build: ^2.0.0 - build_config: ^1.0.0 + analyzer: ">=4.6.0 <6.0.0" + build: ^2.3.1 + build_config: ^1.1.0 collection: ^1.15.0 meta: ^1.7.0 - source_gen: ^1.2.0 + source_gen: ^1.2.3 freezed_annotation: ^2.1.0 - json_annotation: ^4.4.0 + json_annotation: ^4.6.0 dev_dependencies: - json_serializable: ^6.1.3 + json_serializable: ^6.3.2 build_test: ^2.1.5 - build_runner: ^2.1.7 - test: ^1.20.1 + build_runner: ^2.2.0 + test: ^1.21.0 matcher: ^0.12.11 - source_gen_test: ^1.0.2 - expect_error: ^1.0.2 + source_gen_test: ^1.0.4 diff --git a/packages/freezed/pubspec_overrides.yaml b/packages/freezed/pubspec_overrides.yaml index b055cd3e..fcaedda4 100644 --- a/packages/freezed/pubspec_overrides.yaml +++ b/packages/freezed/pubspec_overrides.yaml @@ -1,3 +1,7 @@ dependency_overrides: freezed_annotation: path: ../freezed_annotation + # pub downgrade: + # build_runner 2.2.0 => glob 2.0.0 => file 6.0.0 + # but we need minimum 6.1.3 + file: ^6.1.3 diff --git a/packages/freezed_annotation/pubspec.yaml b/packages/freezed_annotation/pubspec.yaml index db7b0bbb..cbc1cb83 100644 --- a/packages/freezed_annotation/pubspec.yaml +++ b/packages/freezed_annotation/pubspec.yaml @@ -7,14 +7,20 @@ repository: https://github.com/rrousselGit/freezed issue_tracker: https://github.com/rrousselGit/freezed/issues environment: - sdk: ">=2.14.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" dependencies: collection: ^1.15.0 - json_annotation: ^4.4.0 + json_annotation: ^4.6.0 meta: ^1.7.0 dev_dependencies: - build_runner: ^2.1.7 - json_serializable: ^6.1.3 + build_runner: ^2.2.0 + json_serializable: ^6.3.2 test: ^1.21.0 + +dependency_overrides: + # pub downgrade: + # build_runner 2.2.0 => glob 2.0.0 => file 6.0.0 + # but we need minimum 6.1.3 + file: ^6.1.3 From ac473e9874879720865f887c4940c95275ec5cd9 Mon Sep 17 00:00:00 2001 From: David Wimmer Date: Fri, 7 Oct 2022 15:52:38 +0200 Subject: [PATCH 15/23] chore: Cache flutter sdk in the CI (#777) --- .github/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7df7daf8..479ba054 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,11 +28,12 @@ jobs: dependencies: downgrade steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: subosito/flutter-action@v1 + - uses: subosito/flutter-action@v2 with: channel: ${{ matrix.channel }} + cache: ${{ matrix.channel == 'stable' }} # It is executed separately - name: Removing example folder From 6f3bfe8ed151a4597f9eae0ec37035c3cb8b74d1 Mon Sep 17 00:00:00 2001 From: Nicolas Schlecker Date: Sat, 8 Oct 2022 23:22:11 +0200 Subject: [PATCH 16/23] re-add expect_error dependency --- packages/freezed/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/freezed/pubspec.yaml b/packages/freezed/pubspec.yaml index ff5fbf8a..c73821ff 100644 --- a/packages/freezed/pubspec.yaml +++ b/packages/freezed/pubspec.yaml @@ -26,3 +26,4 @@ dev_dependencies: test: ^1.21.0 matcher: ^0.12.11 source_gen_test: ^1.0.4 + expect_error: ^1.0.4 From 41aae940d2e80b1362e41e51b0f24206a80bdb3a Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 29 Nov 2022 14:26:07 +0100 Subject: [PATCH 17/23] Fix error --- packages/freezed/lib/src/freezed_generator.dart | 4 ---- packages/freezed/test/common_types_test.dart | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 2a14446a..9f49b2b9 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -898,7 +898,3 @@ extension Let on T { @pragma('vm:prefer-inline') R let(R Function(T) f) => f(this); } - -extension on DartType { - bool get isNullable => nullabilitySuffix == NullabilitySuffix.question; -} diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index 49173359..11b01a4d 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -93,7 +93,7 @@ void main() { var c = freezedClass.getGetter('c')!.returnType; expect(c, isA()); - expect(c.element2!.name, equals('String')); + expect(c.element!.name, equals('String')); var e = freezedClass.getGetter('genericTypedef')!.returnType; expect(e, isA()); From 253ae77fd0c8fa0ccd5a148b49c9a01b9cd28c3f Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 29 Nov 2022 14:35:33 +0100 Subject: [PATCH 18/23] Cleanup --- packages/freezed/lib/src/freezed_generator.dart | 6 +++--- .../lib/src/templates/abstract_template.dart | 7 +++++-- .../freezed/lib/src/templates/properties.dart | 15 ++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 9f49b2b9..8733784f 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -128,7 +128,7 @@ class FreezedGenerator extends ParserGenerator { List _commonProperties( List constructorsNeedsGeneration, ) { - return _commonPropertiesBetweenAllConstructors(constructorsNeedsGeneration) + return _commonParametersBetweenAllConstructors(constructorsNeedsGeneration) .map(Property.fromParameter) .toList(); } @@ -229,7 +229,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return false; } - List _commonPropertiesBetweenAllConstructors( + List _commonParametersBetweenAllConstructors( List constructorsNeedsGeneration, ) { return constructorsNeedsGeneration.first.parameters.allParameters @@ -656,7 +656,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C final commonProperties = _commonProperties(data.constructors); final commonCopyableProperties = - commonProperties.where((p) => p.isCopyable).toList(); + commonProperties.where((p) => p.isDowncastedAsCommonProperty).toList(); final commonCopyWith = !data.generateCopyWith ? null diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 6173e798..f36af9c4 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -19,17 +19,20 @@ class Abstract { String toString() { final abstractProperties = commonProperties .expand((e) { - return [ + return [ e.unimplementedGetter, if (!e.isFinal && // Don't add a setter for a field where the setters type is not // a subtype of the getters type. + // This happens when a property shared between union cases + // is downcasted, such as if one case uses int and another uses double. + // In that scenario, the getter would be of type num. But a + // setter of type num wouldn't make sense !(e.commonSupertype != null && e.commonSubtype != e.commonSupertype)) e.unimplementedSetter, ]; }) - .whereType() .map((e) => e.toString()) .join(); diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index d85cf2c2..6e8133e9 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -102,7 +102,12 @@ class Property { final String? commonSupertype; final String? commonSubtype; - bool get isCopyable => commonSupertype == commonSubtype; + /// When a property is shared between union cases, this boolean + /// presents whether the union cases define a property within the same name + /// but different type. + /// + /// In that scenario, the abstract class uses a downcasted version of the property. + bool get isDowncastedAsCommonProperty => commonSupertype == commonSubtype; @override String toString() { @@ -187,11 +192,7 @@ class Property { } } -class ClassMember { - const ClassMember(); -} - -class Getter implements ClassMember { +class Getter { Getter({ required String? type, required this.name, @@ -212,7 +213,7 @@ class Getter implements ClassMember { } } -class Setter implements ClassMember { +class Setter { Setter({ required String? type, required this.name, From eb731cc8f9d212348fc54f50deb96bcdbdbb7807 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 29 Nov 2022 15:10:41 +0100 Subject: [PATCH 19/23] Improve tests --- packages/freezed/test/common_types_test.dart | 39 +++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index 11b01a4d..c6b12ad3 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: omit_local_variable_types + import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; @@ -28,18 +30,18 @@ Future main() async { group('CommonSuperSubtype', () { test('has the common properties available', () { - var value = const CommonSuperSubtype('a', 1337, 42.24); - expect(value.a, 'a'); - expect(value.a, isA()); - expect(value.b, 1337); - expect(value.b, isA()); - expect(value.c, 42.24); - expect(value.c, isA()); - - value = const CommonSuperSubtype.named('b', 12.34, 56.78); - expect(value.a, 'b'); - expect(value.b, 12.34); - expect(value.c, 56.78); + const value = CommonSuperSubtype('a', 1337, 42.24); + String? a = value.a; + expect(a, 'a'); + num b = value.b; + expect(b, 1337); + num c = value.c; + expect(c, 42.24); + + const value2 = CommonSuperSubtype.named('b', 12.34, 56.78); + expect(value2.a, 'b'); + expect(value2.b, 12.34); + expect(value2.c, 56.78); }); }); @@ -104,11 +106,12 @@ void main() { group('CommonUnfreezed', () { test('should have common getters available', () { - var value = CommonUnfreezed.one(a: 42, b: 3.14); - expect(value.a, 42); - expect(value.a, isA()); - expect(value.b, 3.14); - expect(value.b, isA()); + final value = CommonUnfreezed.one(a: 42, b: 3.14); + + num a = value.a; + expect(a, 42); + double b = value.b; + expect(b, 3.14); }); test('should not have setters for getters with different type', () async { @@ -119,6 +122,8 @@ void main() { final param = CommonUnfreezed.one(a: 42, b: 3.14); // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER param.a = 42.24; + // OK since all union cases are typed the same + param.b = 42; } '''), compiles); }); From 4e798fb5e2d9c1a76cab500fa3add2555da959b1 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 29 Nov 2022 15:37:06 +0100 Subject: [PATCH 20/23] Remove generated/typedef support --- .../freezed/lib/src/freezed_generator.dart | 96 +++++-------------- .../lib/src/templates/abstract_template.dart | 20 +--- packages/freezed/lib/src/utils.dart | 13 --- packages/freezed/test/common_types_test.dart | 35 ------- .../test/integration/common_types.dart | 35 ------- 5 files changed, 28 insertions(+), 171 deletions(-) diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 8733784f..e2a4016a 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -236,82 +236,39 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C .map((parameter) { final library = parameter.parameterElement!.library!; - String typeString(DartType type, {bool withNullability = true}) { - return resolveFullTypeStringFrom( - library, - type, - withNullability: withNullability, - ); - } - - var anyMatchingPropertyIsFinal = false; - - var commonSupertype = parameter.parameterElement!.type; - var commonSubtype = parameter.parameterElement?.type; - - // Required fallback type for when common types can't be resolved - // using the type system - String? commonSupertypeString; - String? commonSubtypeString; + var anyMatchingPropertyIsFinal = parameter.isFinal; + var commonTypeBetweenAllUnionConstructors = + parameter.parameterElement!.type; + // skip(1) as "parameter" is from the first constructor. for (final constructor in constructorsNeedsGeneration.skip(1)) { final matchingParameter = constructor.parameters.allParameters .firstWhereOrNull((p) => p.name == parameter.name); - + // The property is not present in one of the union cases, so shouldn't + // be present in the abstract class. if (matchingParameter == null) return null; + anyMatchingPropertyIsFinal = + anyMatchingPropertyIsFinal || matchingParameter.isFinal; - final matchingParameterType = - matchingParameter.parameterElement!.type; - if (matchingParameter.isFinal) anyMatchingPropertyIsFinal = true; - - if (commonSupertype is FunctionType || commonSupertype.isDynamic) { - // If the type is a typedef, by finding the upper bound we would lose - // the initial definition. Therefore FunctionTypes are currently not - // supported as common super types. - // => Fall back to type string matching. - commonSupertypeString ??= parameter.type!; - if (commonSupertypeString.contains('dynamic')) return null; - - if (!typeStringsEqualIgnoringNullability( - commonSupertypeString, matchingParameter.type!)) { - return null; - } - - if (commonSupertype.isNullable != - matchingParameterType.isNullable) { - commonSupertypeString = - typeStringWithNullability(commonSupertypeString); - commonSubtypeString = - typeStringWithoutNullability(commonSupertypeString); - } - } else { - commonSupertype = library.typeSystem.leastUpperBound( - commonSupertype, - matchingParameterType, - ); - - if (commonSupertype - .getDisplayString(withNullability: true) - .contains('dynamic')) return null; - - if (commonSubtype != null) { - if (library.typeSystem - .isSubtypeOf(matchingParameterType, commonSubtype)) { - commonSubtype = matchingParameterType; - } else if (!library.typeSystem - .isSubtypeOf(commonSubtype, matchingParameterType)) { - commonSubtype = null; - } - } - } + commonTypeBetweenAllUnionConstructors = + library.typeSystem.leastUpperBound( + commonTypeBetweenAllUnionConstructors, + matchingParameter.parameterElement!.type, + ); } + final commonTypeString = resolveFullTypeStringFrom( + library, + commonTypeBetweenAllUnionConstructors, + withNullability: true, + ); + return parameter.copyWith( - isFinal: parameter.isFinal || anyMatchingPropertyIsFinal, - commonSupertype: - commonSupertypeString ?? typeString(commonSupertype), - commonSubtype: - commonSubtypeString ?? commonSubtype?.let(typeString), + isFinal: anyMatchingPropertyIsFinal || + // The field was downcasted because some union cases use a + // different type for that field. As such, there is no valid setter + parameter.type != commonTypeString, + type: commonTypeString, ); }) .whereNotNull() @@ -893,8 +850,3 @@ String? parseLateGetterSource(String source) { } return null; } - -extension Let on T { - @pragma('vm:prefer-inline') - R let(R Function(T) f) => f(this); -} diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index f36af9c4..9e9b6234 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -18,22 +18,10 @@ class Abstract { @override String toString() { final abstractProperties = commonProperties - .expand((e) { - return [ - e.unimplementedGetter, - if (!e.isFinal && - // Don't add a setter for a field where the setters type is not - // a subtype of the getters type. - // This happens when a property shared between union cases - // is downcasted, such as if one case uses int and another uses double. - // In that scenario, the getter would be of type num. But a - // setter of type num wouldn't make sense - !(e.commonSupertype != null && - e.commonSubtype != e.commonSupertype)) - e.unimplementedSetter, - ]; - }) - .map((e) => e.toString()) + .expand((e) => [ + e.unimplementedGetter, + if (!e.isFinal) e.unimplementedSetter, + ]) .join(); return ''' diff --git a/packages/freezed/lib/src/utils.dart b/packages/freezed/lib/src/utils.dart index 1b4546a0..39687221 100644 --- a/packages/freezed/lib/src/utils.dart +++ b/packages/freezed/lib/src/utils.dart @@ -71,16 +71,3 @@ String _fixCase(String input, String separator) => return lower; }); - -String typeStringWithoutNullability(String typeString) { - return typeString.replaceAll(RegExp(r'\?$'), ''); -} - -String typeStringWithNullability(String typeString) { - return typeString.endsWith('?') ? typeString : '$typeString?'; -} - -bool typeStringsEqualIgnoringNullability(String typeA, String typeB) { - return typeStringWithoutNullability(typeA) == - typeStringWithoutNullability(typeB); -} diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index c6b12ad3..a14ba948 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -1,8 +1,6 @@ // ignore_for_file: omit_local_variable_types import 'package:analyzer/dart/analysis/results.dart'; -import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/type.dart'; import 'package:build_test/build_test.dart'; import 'package:expect_error/expect_error.dart'; import 'package:test/test.dart'; @@ -71,39 +69,6 @@ void main() { }); }); - group('CommonTypedefs', () { - test('generates correct typedefs', () async { - final main = await resolveSources( - { - 'freezed|test/integration/common_types.dart': useAssetReader, - }, - (r) => r.libraries.firstWhere( - (element) => element.source.toString().contains('common_types')), - ); - - var freezedClass = main.topLevelElements - .whereType() - .firstWhere((element) => element.displayName == r'_$CommonTypedefs'); - - var a = freezedClass.getGetter('a')!.returnType; - expect(a, isA()); - expect(a.alias!.element.name, equals('ExternalTypedef')); - - var b = freezedClass.getGetter('b')!.returnType; - expect(b, isA()); - expect(b.alias!.element.name, equals('ExternalTypedefTwo')); - - var c = freezedClass.getGetter('c')!.returnType; - expect(c, isA()); - expect(c.element!.name, equals('String')); - - var e = freezedClass.getGetter('genericTypedef')!.returnType; - expect(e, isA()); - expect(e.alias!.element.name, equals('GenericTypedef')); - expect(e.alias!.typeArguments.toString(), equals('[int, bool]')); - }); - }); - group('CommonUnfreezed', () { test('should have common getters available', () { final value = CommonUnfreezed.one(a: 42, b: 3.14); diff --git a/packages/freezed/test/integration/common_types.dart b/packages/freezed/test/integration/common_types.dart index 68781df8..adfb7dfd 100644 --- a/packages/freezed/test/integration/common_types.dart +++ b/packages/freezed/test/integration/common_types.dart @@ -1,23 +1,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import 'external_typedef.dart'; -import 'external_typedef_two.dart' as two; -import 'typedef_parameter.dart'; part 'common_types.freezed.dart'; -@freezed -class Dependency with _$Dependency { - const factory Dependency() = Dependency0; -} - -@freezed -class GeneratedDependency with _$GeneratedDependency { - const factory GeneratedDependency(Dependency0 a) = _GeneratedDependency0; - - const factory GeneratedDependency.named({required Dependency0 a}) = - _GeneratedDependency1; -} - @freezed class CommonSuperSubtype with _$CommonSuperSubtype { const factory CommonSuperSubtype( @@ -64,25 +48,6 @@ class CommonInterfaceSupertype with _$CommonInterfaceSupertype { ) = CommonInterfaceSupertype2; } -typedef TypedefString = String; - -@freezed -class CommonTypedefs with _$CommonTypedefs { - const factory CommonTypedefs.one({ - required ExternalTypedef a, - required two.ExternalTypedefTwo b, - required TypedefString c, - required GenericTypedef genericTypedef, - }) = CommonTypedefsOne; - - const factory CommonTypedefs.two({ - required ExternalTypedef? a, - required two.ExternalTypedefTwo? b, - required TypedefString? c, - required GenericTypedef genericTypedef, - }) = CommonTypedefsTwo; -} - @freezed class CommonTypeNested with _$CommonTypeNested { const factory CommonTypeNested.one({required int a}) = CommonTypeNestedOne; From 07e7ce279498a70daf3d499e534abd68a84fbee7 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 29 Nov 2022 16:15:23 +0100 Subject: [PATCH 21/23] Update tests --- packages/freezed/test/common_types_test.dart | 110 +++++++++++++----- .../test/integration/common_types.dart | 52 ++------- 2 files changed, 92 insertions(+), 70 deletions(-) diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index a14ba948..e5f81406 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -1,4 +1,4 @@ -// ignore_for_file: omit_local_variable_types +// ignore_for_file: omit_local_variable_types, unused_local_variable import 'package:analyzer/dart/analysis/results.dart'; import 'package:build_test/build_test.dart'; @@ -27,43 +27,97 @@ Future main() async { }); group('CommonSuperSubtype', () { - test('has the common properties available', () { - const value = CommonSuperSubtype('a', 1337, 42.24); - String? a = value.a; - expect(a, 'a'); - num b = value.b; - expect(b, 1337); - num c = value.c; - expect(c, 42.24); - - const value2 = CommonSuperSubtype.named('b', 12.34, 56.78); - expect(value2.a, 'b'); - expect(value2.b, 12.34); - expect(value2.c, 56.78); + test('on the shared interface, has the common properties available', () { + const value = CommonSuperSubtype( + nullabilityDifference: 42, + typeDifference: 21, + ); + int? nullabilityDifference = value.nullabilityDifference; + num typeDifference = value.typeDifference; + + expect(value.nullabilityDifference, 42); + expect(value.typeDifference, 21); + + const value2 = CommonSuperSubtype.named( + nullabilityDifference: null, + typeDifference: 22, + ); + expect(value2.nullabilityDifference, null); + expect(value2.typeDifference, 22); }); - }); - group('GeneratedDependency', () { - test('should have getters available', () async { - final param = const GeneratedDependency(Dependency0()); - expect(param.a, isA()); + test('on the subclass, properties use explicit type', () { + const value = CommonSuperSubtype0( + nullabilityDifference: 42, + typeDifference: 21, + ); + int nullabilityDifference = value.nullabilityDifference; + int typeDifference = value.typeDifference; + + expect(value.nullabilityDifference, 42); + expect(value.typeDifference, 21); + + const value2 = CommonSuperSubtype1( + nullabilityDifference: null, + typeDifference: 22, + ); + int? nullabilityDifference2 = value2.nullabilityDifference; + double typeDifference2 = value2.typeDifference; + + expect(value2.nullabilityDifference, null); + expect(value2.typeDifference, 22); + }); + + test( + 'should not have getters for properties that are not shared between all unions', + () async { + await expectLater(library.withCode(''' +import 'integration/common_types.dart'; + +void main() { + const value = CommonSuperSubtype( + nullabilityDifference: 42, + typeDifference: 21, + ); + // expect-error: UNDEFINED_GETTER + value.unknown; +} +'''), compiles); }); - }); - group('CommonInterfaceSupertype', () { - test('has common param available', () { - var value = const CommonInterfaceSupertype(CommonInterfaceB()); - expect(value.param, isA()); + test('Can clone properties with nullability difference', () { + const value = CommonSuperSubtype0( + nullabilityDifference: 42, + typeDifference: 21, + ); + + expect( + value.copyWith(nullabilityDifference: 84), + const CommonSuperSubtype0( + nullabilityDifference: 84, + typeDifference: 21, + ), + ); }); - test('does not have copy available', () async { + test('Cannot clone with type mismatch', () async { await expectLater(library.withCode(''' import 'integration/common_types.dart'; void main() { - CommonInterfaceSupertype param = CommonInterfaceSupertype(CommonInterfaceB()); - // expect-error: UNDEFINED_METHOD - param.copyWith(); + final param = CommonSuperSubtype( + nullabilityDifference: 42, + typeDifference: 21, + ); + param.copyWith( + // Since not all unions have a nullable property, we cannot assign "null" + // on the shared interface. + // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER + nullabilityDifference: null, + // Since not all unions use the same type, we can't clone that property at all. + // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER + typeDifference: 42, + ); } '''), compiles); }); diff --git a/packages/freezed/test/integration/common_types.dart b/packages/freezed/test/integration/common_types.dart index adfb7dfd..e2dac320 100644 --- a/packages/freezed/test/integration/common_types.dart +++ b/packages/freezed/test/integration/common_types.dart @@ -4,48 +4,16 @@ part 'common_types.freezed.dart'; @freezed class CommonSuperSubtype with _$CommonSuperSubtype { - const factory CommonSuperSubtype( - String a, - int b, - double c, - ) = CommonSuperSubtype0; - - const factory CommonSuperSubtype.named( - String? a, - double b, - num c, - ) = CommonSuperSubtype1; -} - -class CommonInterface { - const CommonInterface(); -} - -class CommonInterfaceA implements CommonInterface { - const CommonInterfaceA(); -} - -class CommonInterfaceB implements CommonInterfaceA { - const CommonInterfaceB(); -} - -class CommonInterfaceC implements CommonInterface { - const CommonInterfaceC(); -} - -@freezed -class CommonInterfaceSupertype with _$CommonInterfaceSupertype { - const factory CommonInterfaceSupertype( - CommonInterfaceA param, - ) = CommonInterfaceSupertype0; - - const factory CommonInterfaceSupertype.one( - CommonInterfaceB param, - ) = CommonInterfaceSupertype1; - - const factory CommonInterfaceSupertype.two( - CommonInterfaceC param, - ) = CommonInterfaceSupertype2; + const factory CommonSuperSubtype({ + required int nullabilityDifference, + required int typeDifference, + String? unknown, + }) = CommonSuperSubtype0; + + const factory CommonSuperSubtype.named({ + required int? nullabilityDifference, + required double typeDifference, + }) = CommonSuperSubtype1; } @freezed From c578a5eca9d64150e339d45fb049735cc4948407 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 30 Nov 2022 14:54:24 +0100 Subject: [PATCH 22/23] Fix tests and handle {int a}|{int? a}.copyWith({int a}) --- packages/_internal/lib/models.dart | 8 +- packages/_internal/lib/models.freezed.dart | 1086 ++++++++--------- packages/_internal/pubspec.lock | 273 +++-- packages/_internal/pubspec.yaml | 4 +- .../freezed/lib/src/freezed_generator.dart | 156 ++- packages/freezed/lib/src/models.dart | 8 +- packages/freezed/lib/src/models.freezed.dart | 1086 ++++++++--------- .../lib/src/templates/abstract_template.dart | 2 +- .../freezed/lib/src/templates/copy_with.dart | 194 +-- packages/freezed/test/common_types_test.dart | 64 +- .../test/integration/common_types.dart | 13 +- 11 files changed, 1436 insertions(+), 1458 deletions(-) diff --git a/packages/_internal/lib/models.dart b/packages/_internal/lib/models.dart index be0a2673..7046bdf5 100644 --- a/packages/_internal/lib/models.dart +++ b/packages/_internal/lib/models.dart @@ -25,14 +25,14 @@ String constructorNameToCallbackName(String name) => name; /// This allows Freezed to support deep copy of the object. /// This does include primitives like [int] and [List]. @freezed -class CloneableProperty with _$CloneableProperty { - factory CloneableProperty({ +class DeepCloneableProperty with _$DeepCloneableProperty { + factory DeepCloneableProperty({ required String name, required String typeName, required String type, required bool nullable, required GenericsParameterTemplate genericParameters, - }) = _CloneableProperty; + }) = _DeepCloneableProperty; } /// The information of a specific constructor of a class tagged with `@freezed`. @@ -55,7 +55,7 @@ class ConstructorDetails with _$ConstructorDetails { required List withDecorators, required List implementsDecorators, required List decorators, - required List cloneableProperties, + required List cloneableProperties, required List asserts, }) = _ConstructorDetails; diff --git a/packages/_internal/lib/models.freezed.dart b/packages/_internal/lib/models.freezed.dart index 85eb285a..e182134d 100644 --- a/packages/_internal/lib/models.freezed.dart +++ b/packages/_internal/lib/models.freezed.dart @@ -1,5 +1,6 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target part of 'models.dart'; @@ -14,30 +15,7 @@ final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); /// @nodoc -class _$CloneablePropertyTearOff { - const _$CloneablePropertyTearOff(); - - _CloneableProperty call( - {required String name, - required String typeName, - required String type, - required bool nullable, - required GenericsParameterTemplate genericParameters}) { - return _CloneableProperty( - name: name, - typeName: typeName, - type: type, - nullable: nullable, - genericParameters: genericParameters, - ); - } -} - -/// @nodoc -const $CloneableProperty = _$CloneablePropertyTearOff(); - -/// @nodoc -mixin _$CloneableProperty { +mixin _$DeepCloneableProperty { String get name => throw _privateConstructorUsedError; String get typeName => throw _privateConstructorUsedError; String get type => throw _privateConstructorUsedError; @@ -46,15 +24,16 @@ mixin _$CloneableProperty { throw _privateConstructorUsedError; @JsonKey(ignore: true) - $CloneablePropertyCopyWith get copyWith => + $DeepCloneablePropertyCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $CloneablePropertyCopyWith<$Res> { - factory $CloneablePropertyCopyWith( - CloneableProperty value, $Res Function(CloneableProperty) then) = - _$CloneablePropertyCopyWithImpl<$Res>; +abstract class $DeepCloneablePropertyCopyWith<$Res> { + factory $DeepCloneablePropertyCopyWith(DeepCloneableProperty value, + $Res Function(DeepCloneableProperty) then) = + _$DeepCloneablePropertyCopyWithImpl<$Res, DeepCloneableProperty>; + @useResult $Res call( {String name, String typeName, @@ -64,54 +43,58 @@ abstract class $CloneablePropertyCopyWith<$Res> { } /// @nodoc -class _$CloneablePropertyCopyWithImpl<$Res> - implements $CloneablePropertyCopyWith<$Res> { - _$CloneablePropertyCopyWithImpl(this._value, this._then); +class _$DeepCloneablePropertyCopyWithImpl<$Res, + $Val extends DeepCloneableProperty> + implements $DeepCloneablePropertyCopyWith<$Res> { + _$DeepCloneablePropertyCopyWithImpl(this._value, this._then); - final CloneableProperty _value; // ignore: unused_field - final $Res Function(CloneableProperty) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? typeName = freezed, - Object? type = freezed, - Object? nullable = freezed, - Object? genericParameters = freezed, + Object? name = null, + Object? typeName = null, + Object? type = null, + Object? nullable = null, + Object? genericParameters = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - typeName: typeName == freezed + typeName: null == typeName ? _value.typeName : typeName // ignore: cast_nullable_to_non_nullable as String, - type: type == freezed + type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - nullable: nullable == freezed + nullable: null == nullable ? _value.nullable : nullable // ignore: cast_nullable_to_non_nullable as bool, - genericParameters: genericParameters == freezed + genericParameters: null == genericParameters ? _value.genericParameters : genericParameters // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - )); + ) as $Val); } } /// @nodoc -abstract class _$CloneablePropertyCopyWith<$Res> - implements $CloneablePropertyCopyWith<$Res> { - factory _$CloneablePropertyCopyWith( - _CloneableProperty value, $Res Function(_CloneableProperty) then) = - __$CloneablePropertyCopyWithImpl<$Res>; +abstract class _$$_DeepCloneablePropertyCopyWith<$Res> + implements $DeepCloneablePropertyCopyWith<$Res> { + factory _$$_DeepCloneablePropertyCopyWith(_$_DeepCloneableProperty value, + $Res Function(_$_DeepCloneableProperty) then) = + __$$_DeepCloneablePropertyCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String typeName, @@ -121,42 +104,40 @@ abstract class _$CloneablePropertyCopyWith<$Res> } /// @nodoc -class __$CloneablePropertyCopyWithImpl<$Res> - extends _$CloneablePropertyCopyWithImpl<$Res> - implements _$CloneablePropertyCopyWith<$Res> { - __$CloneablePropertyCopyWithImpl( - _CloneableProperty _value, $Res Function(_CloneableProperty) _then) - : super(_value, (v) => _then(v as _CloneableProperty)); - - @override - _CloneableProperty get _value => super._value as _CloneableProperty; +class __$$_DeepCloneablePropertyCopyWithImpl<$Res> + extends _$DeepCloneablePropertyCopyWithImpl<$Res, _$_DeepCloneableProperty> + implements _$$_DeepCloneablePropertyCopyWith<$Res> { + __$$_DeepCloneablePropertyCopyWithImpl(_$_DeepCloneableProperty _value, + $Res Function(_$_DeepCloneableProperty) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? typeName = freezed, - Object? type = freezed, - Object? nullable = freezed, - Object? genericParameters = freezed, + Object? name = null, + Object? typeName = null, + Object? type = null, + Object? nullable = null, + Object? genericParameters = null, }) { - return _then(_CloneableProperty( - name: name == freezed + return _then(_$_DeepCloneableProperty( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - typeName: typeName == freezed + typeName: null == typeName ? _value.typeName : typeName // ignore: cast_nullable_to_non_nullable as String, - type: type == freezed + type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - nullable: nullable == freezed + nullable: null == nullable ? _value.nullable : nullable // ignore: cast_nullable_to_non_nullable as bool, - genericParameters: genericParameters == freezed + genericParameters: null == genericParameters ? _value.genericParameters : genericParameters // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, @@ -166,8 +147,8 @@ class __$CloneablePropertyCopyWithImpl<$Res> /// @nodoc -class _$_CloneableProperty implements _CloneableProperty { - _$_CloneableProperty( +class _$_DeepCloneableProperty implements _DeepCloneableProperty { + _$_DeepCloneableProperty( {required this.name, required this.typeName, required this.type, @@ -187,14 +168,14 @@ class _$_CloneableProperty implements _CloneableProperty { @override String toString() { - return 'CloneableProperty(name: $name, typeName: $typeName, type: $type, nullable: $nullable, genericParameters: $genericParameters)'; + return 'DeepCloneableProperty(name: $name, typeName: $typeName, type: $type, nullable: $nullable, genericParameters: $genericParameters)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _CloneableProperty && + other is _$_DeepCloneableProperty && (identical(other.name, name) || other.name == name) && (identical(other.typeName, typeName) || other.typeName == typeName) && @@ -211,18 +192,20 @@ class _$_CloneableProperty implements _CloneableProperty { @JsonKey(ignore: true) @override - _$CloneablePropertyCopyWith<_CloneableProperty> get copyWith => - __$CloneablePropertyCopyWithImpl<_CloneableProperty>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_DeepCloneablePropertyCopyWith<_$_DeepCloneableProperty> get copyWith => + __$$_DeepCloneablePropertyCopyWithImpl<_$_DeepCloneableProperty>( + this, _$identity); } -abstract class _CloneableProperty implements CloneableProperty { - factory _CloneableProperty( - {required String name, - required String typeName, - required String type, - required bool nullable, - required GenericsParameterTemplate genericParameters}) = - _$_CloneableProperty; +abstract class _DeepCloneableProperty implements DeepCloneableProperty { + factory _DeepCloneableProperty( + {required final String name, + required final String typeName, + required final String type, + required final bool nullable, + required final GenericsParameterTemplate genericParameters}) = + _$_DeepCloneableProperty; @override String get name; @@ -236,55 +219,10 @@ abstract class _CloneableProperty implements CloneableProperty { GenericsParameterTemplate get genericParameters; @override @JsonKey(ignore: true) - _$CloneablePropertyCopyWith<_CloneableProperty> get copyWith => + _$$_DeepCloneablePropertyCopyWith<_$_DeepCloneableProperty> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$ConstructorDetailsTearOff { - const _$ConstructorDetailsTearOff(); - - _ConstructorDetails call( - {required String name, - required String unionValue, - required bool isConst, - required String redirectedName, - required ParametersTemplate parameters, - required List impliedProperties, - required bool isDefault, - required bool isFallback, - required bool hasJsonSerializable, - required String fullName, - required String escapedName, - required List withDecorators, - required List implementsDecorators, - required List decorators, - required List cloneableProperties, - required List asserts}) { - return _ConstructorDetails( - name: name, - unionValue: unionValue, - isConst: isConst, - redirectedName: redirectedName, - parameters: parameters, - impliedProperties: impliedProperties, - isDefault: isDefault, - isFallback: isFallback, - hasJsonSerializable: hasJsonSerializable, - fullName: fullName, - escapedName: escapedName, - withDecorators: withDecorators, - implementsDecorators: implementsDecorators, - decorators: decorators, - cloneableProperties: cloneableProperties, - asserts: asserts, - ); - } -} - -/// @nodoc -const $ConstructorDetails = _$ConstructorDetailsTearOff(); - /// @nodoc mixin _$ConstructorDetails { String get name => throw _privateConstructorUsedError; @@ -301,7 +239,7 @@ mixin _$ConstructorDetails { List get withDecorators => throw _privateConstructorUsedError; List get implementsDecorators => throw _privateConstructorUsedError; List get decorators => throw _privateConstructorUsedError; - List get cloneableProperties => + List get cloneableProperties => throw _privateConstructorUsedError; List get asserts => throw _privateConstructorUsedError; @@ -314,7 +252,8 @@ mixin _$ConstructorDetails { abstract class $ConstructorDetailsCopyWith<$Res> { factory $ConstructorDetailsCopyWith( ConstructorDetails value, $Res Function(ConstructorDetails) then) = - _$ConstructorDetailsCopyWithImpl<$Res>; + _$ConstructorDetailsCopyWithImpl<$Res, ConstructorDetails>; + @useResult $Res call( {String name, String unionValue, @@ -330,114 +269,117 @@ abstract class $ConstructorDetailsCopyWith<$Res> { List withDecorators, List implementsDecorators, List decorators, - List cloneableProperties, + List cloneableProperties, List asserts}); } /// @nodoc -class _$ConstructorDetailsCopyWithImpl<$Res> +class _$ConstructorDetailsCopyWithImpl<$Res, $Val extends ConstructorDetails> implements $ConstructorDetailsCopyWith<$Res> { _$ConstructorDetailsCopyWithImpl(this._value, this._then); - final ConstructorDetails _value; // ignore: unused_field - final $Res Function(ConstructorDetails) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionValue = freezed, - Object? isConst = freezed, - Object? redirectedName = freezed, - Object? parameters = freezed, - Object? impliedProperties = freezed, - Object? isDefault = freezed, - Object? isFallback = freezed, - Object? hasJsonSerializable = freezed, - Object? fullName = freezed, - Object? escapedName = freezed, - Object? withDecorators = freezed, - Object? implementsDecorators = freezed, - Object? decorators = freezed, - Object? cloneableProperties = freezed, - Object? asserts = freezed, + Object? name = null, + Object? unionValue = null, + Object? isConst = null, + Object? redirectedName = null, + Object? parameters = null, + Object? impliedProperties = null, + Object? isDefault = null, + Object? isFallback = null, + Object? hasJsonSerializable = null, + Object? fullName = null, + Object? escapedName = null, + Object? withDecorators = null, + Object? implementsDecorators = null, + Object? decorators = null, + Object? cloneableProperties = null, + Object? asserts = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionValue: unionValue == freezed + unionValue: null == unionValue ? _value.unionValue : unionValue // ignore: cast_nullable_to_non_nullable as String, - isConst: isConst == freezed + isConst: null == isConst ? _value.isConst : isConst // ignore: cast_nullable_to_non_nullable as bool, - redirectedName: redirectedName == freezed + redirectedName: null == redirectedName ? _value.redirectedName : redirectedName // ignore: cast_nullable_to_non_nullable as String, - parameters: parameters == freezed + parameters: null == parameters ? _value.parameters : parameters // ignore: cast_nullable_to_non_nullable as ParametersTemplate, - impliedProperties: impliedProperties == freezed + impliedProperties: null == impliedProperties ? _value.impliedProperties : impliedProperties // ignore: cast_nullable_to_non_nullable as List, - isDefault: isDefault == freezed + isDefault: null == isDefault ? _value.isDefault : isDefault // ignore: cast_nullable_to_non_nullable as bool, - isFallback: isFallback == freezed + isFallback: null == isFallback ? _value.isFallback : isFallback // ignore: cast_nullable_to_non_nullable as bool, - hasJsonSerializable: hasJsonSerializable == freezed + hasJsonSerializable: null == hasJsonSerializable ? _value.hasJsonSerializable : hasJsonSerializable // ignore: cast_nullable_to_non_nullable as bool, - fullName: fullName == freezed + fullName: null == fullName ? _value.fullName : fullName // ignore: cast_nullable_to_non_nullable as String, - escapedName: escapedName == freezed + escapedName: null == escapedName ? _value.escapedName : escapedName // ignore: cast_nullable_to_non_nullable as String, - withDecorators: withDecorators == freezed + withDecorators: null == withDecorators ? _value.withDecorators : withDecorators // ignore: cast_nullable_to_non_nullable as List, - implementsDecorators: implementsDecorators == freezed + implementsDecorators: null == implementsDecorators ? _value.implementsDecorators : implementsDecorators // ignore: cast_nullable_to_non_nullable as List, - decorators: decorators == freezed + decorators: null == decorators ? _value.decorators : decorators // ignore: cast_nullable_to_non_nullable as List, - cloneableProperties: cloneableProperties == freezed + cloneableProperties: null == cloneableProperties ? _value.cloneableProperties : cloneableProperties // ignore: cast_nullable_to_non_nullable - as List, - asserts: asserts == freezed + as List, + asserts: null == asserts ? _value.asserts : asserts // ignore: cast_nullable_to_non_nullable as List, - )); + ) as $Val); } } /// @nodoc -abstract class _$ConstructorDetailsCopyWith<$Res> +abstract class _$$_ConstructorDetailsCopyWith<$Res> implements $ConstructorDetailsCopyWith<$Res> { - factory _$ConstructorDetailsCopyWith( - _ConstructorDetails value, $Res Function(_ConstructorDetails) then) = - __$ConstructorDetailsCopyWithImpl<$Res>; + factory _$$_ConstructorDetailsCopyWith(_$_ConstructorDetails value, + $Res Function(_$_ConstructorDetails) then) = + __$$_ConstructorDetailsCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String unionValue, @@ -453,103 +395,101 @@ abstract class _$ConstructorDetailsCopyWith<$Res> List withDecorators, List implementsDecorators, List decorators, - List cloneableProperties, + List cloneableProperties, List asserts}); } /// @nodoc -class __$ConstructorDetailsCopyWithImpl<$Res> - extends _$ConstructorDetailsCopyWithImpl<$Res> - implements _$ConstructorDetailsCopyWith<$Res> { - __$ConstructorDetailsCopyWithImpl( - _ConstructorDetails _value, $Res Function(_ConstructorDetails) _then) - : super(_value, (v) => _then(v as _ConstructorDetails)); - - @override - _ConstructorDetails get _value => super._value as _ConstructorDetails; +class __$$_ConstructorDetailsCopyWithImpl<$Res> + extends _$ConstructorDetailsCopyWithImpl<$Res, _$_ConstructorDetails> + implements _$$_ConstructorDetailsCopyWith<$Res> { + __$$_ConstructorDetailsCopyWithImpl( + _$_ConstructorDetails _value, $Res Function(_$_ConstructorDetails) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionValue = freezed, - Object? isConst = freezed, - Object? redirectedName = freezed, - Object? parameters = freezed, - Object? impliedProperties = freezed, - Object? isDefault = freezed, - Object? isFallback = freezed, - Object? hasJsonSerializable = freezed, - Object? fullName = freezed, - Object? escapedName = freezed, - Object? withDecorators = freezed, - Object? implementsDecorators = freezed, - Object? decorators = freezed, - Object? cloneableProperties = freezed, - Object? asserts = freezed, + Object? name = null, + Object? unionValue = null, + Object? isConst = null, + Object? redirectedName = null, + Object? parameters = null, + Object? impliedProperties = null, + Object? isDefault = null, + Object? isFallback = null, + Object? hasJsonSerializable = null, + Object? fullName = null, + Object? escapedName = null, + Object? withDecorators = null, + Object? implementsDecorators = null, + Object? decorators = null, + Object? cloneableProperties = null, + Object? asserts = null, }) { - return _then(_ConstructorDetails( - name: name == freezed + return _then(_$_ConstructorDetails( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionValue: unionValue == freezed + unionValue: null == unionValue ? _value.unionValue : unionValue // ignore: cast_nullable_to_non_nullable as String, - isConst: isConst == freezed + isConst: null == isConst ? _value.isConst : isConst // ignore: cast_nullable_to_non_nullable as bool, - redirectedName: redirectedName == freezed + redirectedName: null == redirectedName ? _value.redirectedName : redirectedName // ignore: cast_nullable_to_non_nullable as String, - parameters: parameters == freezed + parameters: null == parameters ? _value.parameters : parameters // ignore: cast_nullable_to_non_nullable as ParametersTemplate, - impliedProperties: impliedProperties == freezed - ? _value.impliedProperties + impliedProperties: null == impliedProperties + ? _value._impliedProperties : impliedProperties // ignore: cast_nullable_to_non_nullable as List, - isDefault: isDefault == freezed + isDefault: null == isDefault ? _value.isDefault : isDefault // ignore: cast_nullable_to_non_nullable as bool, - isFallback: isFallback == freezed + isFallback: null == isFallback ? _value.isFallback : isFallback // ignore: cast_nullable_to_non_nullable as bool, - hasJsonSerializable: hasJsonSerializable == freezed + hasJsonSerializable: null == hasJsonSerializable ? _value.hasJsonSerializable : hasJsonSerializable // ignore: cast_nullable_to_non_nullable as bool, - fullName: fullName == freezed + fullName: null == fullName ? _value.fullName : fullName // ignore: cast_nullable_to_non_nullable as String, - escapedName: escapedName == freezed + escapedName: null == escapedName ? _value.escapedName : escapedName // ignore: cast_nullable_to_non_nullable as String, - withDecorators: withDecorators == freezed - ? _value.withDecorators + withDecorators: null == withDecorators + ? _value._withDecorators : withDecorators // ignore: cast_nullable_to_non_nullable as List, - implementsDecorators: implementsDecorators == freezed - ? _value.implementsDecorators + implementsDecorators: null == implementsDecorators + ? _value._implementsDecorators : implementsDecorators // ignore: cast_nullable_to_non_nullable as List, - decorators: decorators == freezed - ? _value.decorators + decorators: null == decorators + ? _value._decorators : decorators // ignore: cast_nullable_to_non_nullable as List, - cloneableProperties: cloneableProperties == freezed - ? _value.cloneableProperties + cloneableProperties: null == cloneableProperties + ? _value._cloneableProperties : cloneableProperties // ignore: cast_nullable_to_non_nullable - as List, - asserts: asserts == freezed - ? _value.asserts + as List, + asserts: null == asserts + ? _value._asserts : asserts // ignore: cast_nullable_to_non_nullable as List, )); @@ -565,18 +505,24 @@ class _$_ConstructorDetails extends _ConstructorDetails { required this.isConst, required this.redirectedName, required this.parameters, - required this.impliedProperties, + required final List impliedProperties, required this.isDefault, required this.isFallback, required this.hasJsonSerializable, required this.fullName, required this.escapedName, - required this.withDecorators, - required this.implementsDecorators, - required this.decorators, - required this.cloneableProperties, - required this.asserts}) - : super._(); + required final List withDecorators, + required final List implementsDecorators, + required final List decorators, + required final List cloneableProperties, + required final List asserts}) + : _impliedProperties = impliedProperties, + _withDecorators = withDecorators, + _implementsDecorators = implementsDecorators, + _decorators = decorators, + _cloneableProperties = cloneableProperties, + _asserts = asserts, + super._(); @override final String name; @@ -588,8 +534,13 @@ class _$_ConstructorDetails extends _ConstructorDetails { final String redirectedName; @override final ParametersTemplate parameters; + final List _impliedProperties; @override - final List impliedProperties; + List get impliedProperties { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_impliedProperties); + } + @override final bool isDefault; @override @@ -600,16 +551,40 @@ class _$_ConstructorDetails extends _ConstructorDetails { final String fullName; @override final String escapedName; + final List _withDecorators; @override - final List withDecorators; + List get withDecorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_withDecorators); + } + + final List _implementsDecorators; @override - final List implementsDecorators; + List get implementsDecorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_implementsDecorators); + } + + final List _decorators; @override - final List decorators; + List get decorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_decorators); + } + + final List _cloneableProperties; @override - final List cloneableProperties; + List get cloneableProperties { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_cloneableProperties); + } + + final List _asserts; @override - final List asserts; + List get asserts { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_asserts); + } @override String toString() { @@ -620,7 +595,7 @@ class _$_ConstructorDetails extends _ConstructorDetails { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _ConstructorDetails && + other is _$_ConstructorDetails && (identical(other.name, name) || other.name == name) && (identical(other.unionValue, unionValue) || other.unionValue == unionValue) && @@ -630,7 +605,7 @@ class _$_ConstructorDetails extends _ConstructorDetails { (identical(other.parameters, parameters) || other.parameters == parameters) && const DeepCollectionEquality() - .equals(other.impliedProperties, impliedProperties) && + .equals(other._impliedProperties, _impliedProperties) && (identical(other.isDefault, isDefault) || other.isDefault == isDefault) && (identical(other.isFallback, isFallback) || @@ -642,14 +617,14 @@ class _$_ConstructorDetails extends _ConstructorDetails { (identical(other.escapedName, escapedName) || other.escapedName == escapedName) && const DeepCollectionEquality() - .equals(other.withDecorators, withDecorators) && + .equals(other._withDecorators, _withDecorators) && const DeepCollectionEquality() - .equals(other.implementsDecorators, implementsDecorators) && + .equals(other._implementsDecorators, _implementsDecorators) && const DeepCollectionEquality() - .equals(other.decorators, decorators) && + .equals(other._decorators, _decorators) && const DeepCollectionEquality() - .equals(other.cloneableProperties, cloneableProperties) && - const DeepCollectionEquality().equals(other.asserts, asserts)); + .equals(other._cloneableProperties, _cloneableProperties) && + const DeepCollectionEquality().equals(other._asserts, _asserts)); } @override @@ -660,42 +635,44 @@ class _$_ConstructorDetails extends _ConstructorDetails { isConst, redirectedName, parameters, - const DeepCollectionEquality().hash(impliedProperties), + const DeepCollectionEquality().hash(_impliedProperties), isDefault, isFallback, hasJsonSerializable, fullName, escapedName, - const DeepCollectionEquality().hash(withDecorators), - const DeepCollectionEquality().hash(implementsDecorators), - const DeepCollectionEquality().hash(decorators), - const DeepCollectionEquality().hash(cloneableProperties), - const DeepCollectionEquality().hash(asserts)); + const DeepCollectionEquality().hash(_withDecorators), + const DeepCollectionEquality().hash(_implementsDecorators), + const DeepCollectionEquality().hash(_decorators), + const DeepCollectionEquality().hash(_cloneableProperties), + const DeepCollectionEquality().hash(_asserts)); @JsonKey(ignore: true) @override - _$ConstructorDetailsCopyWith<_ConstructorDetails> get copyWith => - __$ConstructorDetailsCopyWithImpl<_ConstructorDetails>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_ConstructorDetailsCopyWith<_$_ConstructorDetails> get copyWith => + __$$_ConstructorDetailsCopyWithImpl<_$_ConstructorDetails>( + this, _$identity); } abstract class _ConstructorDetails extends ConstructorDetails { factory _ConstructorDetails( - {required String name, - required String unionValue, - required bool isConst, - required String redirectedName, - required ParametersTemplate parameters, - required List impliedProperties, - required bool isDefault, - required bool isFallback, - required bool hasJsonSerializable, - required String fullName, - required String escapedName, - required List withDecorators, - required List implementsDecorators, - required List decorators, - required List cloneableProperties, - required List asserts}) = _$_ConstructorDetails; + {required final String name, + required final String unionValue, + required final bool isConst, + required final String redirectedName, + required final ParametersTemplate parameters, + required final List impliedProperties, + required final bool isDefault, + required final bool isFallback, + required final bool hasJsonSerializable, + required final String fullName, + required final String escapedName, + required final List withDecorators, + required final List implementsDecorators, + required final List decorators, + required final List cloneableProperties, + required final List asserts}) = _$_ConstructorDetails; _ConstructorDetails._() : super._(); @override @@ -727,32 +704,15 @@ abstract class _ConstructorDetails extends ConstructorDetails { @override List get decorators; @override - List get cloneableProperties; + List get cloneableProperties; @override List get asserts; @override @JsonKey(ignore: true) - _$ConstructorDetailsCopyWith<_ConstructorDetails> get copyWith => + _$$_ConstructorDetailsCopyWith<_$_ConstructorDetails> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$MapConfigTearOff { - const _$MapConfigTearOff(); - - _MapConfig call( - {required bool map, required bool mapOrNull, required bool maybeMap}) { - return _MapConfig( - map: map, - mapOrNull: mapOrNull, - maybeMap: maybeMap, - ); - } -} - -/// @nodoc -const $MapConfig = _$MapConfigTearOff(); - /// @nodoc mixin _$MapConfig { bool get map => throw _privateConstructorUsedError; @@ -767,75 +727,80 @@ mixin _$MapConfig { /// @nodoc abstract class $MapConfigCopyWith<$Res> { factory $MapConfigCopyWith(MapConfig value, $Res Function(MapConfig) then) = - _$MapConfigCopyWithImpl<$Res>; + _$MapConfigCopyWithImpl<$Res, MapConfig>; + @useResult $Res call({bool map, bool mapOrNull, bool maybeMap}); } /// @nodoc -class _$MapConfigCopyWithImpl<$Res> implements $MapConfigCopyWith<$Res> { +class _$MapConfigCopyWithImpl<$Res, $Val extends MapConfig> + implements $MapConfigCopyWith<$Res> { _$MapConfigCopyWithImpl(this._value, this._then); - final MapConfig _value; // ignore: unused_field - final $Res Function(MapConfig) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? map = freezed, - Object? mapOrNull = freezed, - Object? maybeMap = freezed, + Object? map = null, + Object? mapOrNull = null, + Object? maybeMap = null, }) { return _then(_value.copyWith( - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as bool, - mapOrNull: mapOrNull == freezed + mapOrNull: null == mapOrNull ? _value.mapOrNull : mapOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeMap: maybeMap == freezed + maybeMap: null == maybeMap ? _value.maybeMap : maybeMap // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$MapConfigCopyWith<$Res> implements $MapConfigCopyWith<$Res> { - factory _$MapConfigCopyWith( - _MapConfig value, $Res Function(_MapConfig) then) = - __$MapConfigCopyWithImpl<$Res>; +abstract class _$$_MapConfigCopyWith<$Res> implements $MapConfigCopyWith<$Res> { + factory _$$_MapConfigCopyWith( + _$_MapConfig value, $Res Function(_$_MapConfig) then) = + __$$_MapConfigCopyWithImpl<$Res>; @override + @useResult $Res call({bool map, bool mapOrNull, bool maybeMap}); } /// @nodoc -class __$MapConfigCopyWithImpl<$Res> extends _$MapConfigCopyWithImpl<$Res> - implements _$MapConfigCopyWith<$Res> { - __$MapConfigCopyWithImpl(_MapConfig _value, $Res Function(_MapConfig) _then) - : super(_value, (v) => _then(v as _MapConfig)); - - @override - _MapConfig get _value => super._value as _MapConfig; +class __$$_MapConfigCopyWithImpl<$Res> + extends _$MapConfigCopyWithImpl<$Res, _$_MapConfig> + implements _$$_MapConfigCopyWith<$Res> { + __$$_MapConfigCopyWithImpl( + _$_MapConfig _value, $Res Function(_$_MapConfig) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? map = freezed, - Object? mapOrNull = freezed, - Object? maybeMap = freezed, + Object? map = null, + Object? mapOrNull = null, + Object? maybeMap = null, }) { - return _then(_MapConfig( - map: map == freezed + return _then(_$_MapConfig( + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as bool, - mapOrNull: mapOrNull == freezed + mapOrNull: null == mapOrNull ? _value.mapOrNull : mapOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeMap: maybeMap == freezed + maybeMap: null == maybeMap ? _value.maybeMap : maybeMap // ignore: cast_nullable_to_non_nullable as bool, @@ -865,7 +830,7 @@ class _$_MapConfig implements _MapConfig { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _MapConfig && + other is _$_MapConfig && (identical(other.map, map) || other.map == map) && (identical(other.mapOrNull, mapOrNull) || other.mapOrNull == mapOrNull) && @@ -878,15 +843,16 @@ class _$_MapConfig implements _MapConfig { @JsonKey(ignore: true) @override - _$MapConfigCopyWith<_MapConfig> get copyWith => - __$MapConfigCopyWithImpl<_MapConfig>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_MapConfigCopyWith<_$_MapConfig> get copyWith => + __$$_MapConfigCopyWithImpl<_$_MapConfig>(this, _$identity); } abstract class _MapConfig implements MapConfig { factory _MapConfig( - {required bool map, - required bool mapOrNull, - required bool maybeMap}) = _$_MapConfig; + {required final bool map, + required final bool mapOrNull, + required final bool maybeMap}) = _$_MapConfig; @override bool get map; @@ -896,27 +862,10 @@ abstract class _MapConfig implements MapConfig { bool get maybeMap; @override @JsonKey(ignore: true) - _$MapConfigCopyWith<_MapConfig> get copyWith => + _$$_MapConfigCopyWith<_$_MapConfig> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$WhenConfigTearOff { - const _$WhenConfigTearOff(); - - _WhenConfig call( - {required bool when, required bool whenOrNull, required bool maybeWhen}) { - return _WhenConfig( - when: when, - whenOrNull: whenOrNull, - maybeWhen: maybeWhen, - ); - } -} - -/// @nodoc -const $WhenConfig = _$WhenConfigTearOff(); - /// @nodoc mixin _$WhenConfig { bool get when => throw _privateConstructorUsedError; @@ -932,76 +881,81 @@ mixin _$WhenConfig { abstract class $WhenConfigCopyWith<$Res> { factory $WhenConfigCopyWith( WhenConfig value, $Res Function(WhenConfig) then) = - _$WhenConfigCopyWithImpl<$Res>; + _$WhenConfigCopyWithImpl<$Res, WhenConfig>; + @useResult $Res call({bool when, bool whenOrNull, bool maybeWhen}); } /// @nodoc -class _$WhenConfigCopyWithImpl<$Res> implements $WhenConfigCopyWith<$Res> { +class _$WhenConfigCopyWithImpl<$Res, $Val extends WhenConfig> + implements $WhenConfigCopyWith<$Res> { _$WhenConfigCopyWithImpl(this._value, this._then); - final WhenConfig _value; // ignore: unused_field - final $Res Function(WhenConfig) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? when = freezed, - Object? whenOrNull = freezed, - Object? maybeWhen = freezed, + Object? when = null, + Object? whenOrNull = null, + Object? maybeWhen = null, }) { return _then(_value.copyWith( - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as bool, - whenOrNull: whenOrNull == freezed + whenOrNull: null == whenOrNull ? _value.whenOrNull : whenOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeWhen: maybeWhen == freezed + maybeWhen: null == maybeWhen ? _value.maybeWhen : maybeWhen // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$WhenConfigCopyWith<$Res> implements $WhenConfigCopyWith<$Res> { - factory _$WhenConfigCopyWith( - _WhenConfig value, $Res Function(_WhenConfig) then) = - __$WhenConfigCopyWithImpl<$Res>; +abstract class _$$_WhenConfigCopyWith<$Res> + implements $WhenConfigCopyWith<$Res> { + factory _$$_WhenConfigCopyWith( + _$_WhenConfig value, $Res Function(_$_WhenConfig) then) = + __$$_WhenConfigCopyWithImpl<$Res>; @override + @useResult $Res call({bool when, bool whenOrNull, bool maybeWhen}); } /// @nodoc -class __$WhenConfigCopyWithImpl<$Res> extends _$WhenConfigCopyWithImpl<$Res> - implements _$WhenConfigCopyWith<$Res> { - __$WhenConfigCopyWithImpl( - _WhenConfig _value, $Res Function(_WhenConfig) _then) - : super(_value, (v) => _then(v as _WhenConfig)); - - @override - _WhenConfig get _value => super._value as _WhenConfig; +class __$$_WhenConfigCopyWithImpl<$Res> + extends _$WhenConfigCopyWithImpl<$Res, _$_WhenConfig> + implements _$$_WhenConfigCopyWith<$Res> { + __$$_WhenConfigCopyWithImpl( + _$_WhenConfig _value, $Res Function(_$_WhenConfig) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? when = freezed, - Object? whenOrNull = freezed, - Object? maybeWhen = freezed, + Object? when = null, + Object? whenOrNull = null, + Object? maybeWhen = null, }) { - return _then(_WhenConfig( - when: when == freezed + return _then(_$_WhenConfig( + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as bool, - whenOrNull: whenOrNull == freezed + whenOrNull: null == whenOrNull ? _value.whenOrNull : whenOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeWhen: maybeWhen == freezed + maybeWhen: null == maybeWhen ? _value.maybeWhen : maybeWhen // ignore: cast_nullable_to_non_nullable as bool, @@ -1031,7 +985,7 @@ class _$_WhenConfig implements _WhenConfig { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _WhenConfig && + other is _$_WhenConfig && (identical(other.when, when) || other.when == when) && (identical(other.whenOrNull, whenOrNull) || other.whenOrNull == whenOrNull) && @@ -1044,15 +998,16 @@ class _$_WhenConfig implements _WhenConfig { @JsonKey(ignore: true) @override - _$WhenConfigCopyWith<_WhenConfig> get copyWith => - __$WhenConfigCopyWithImpl<_WhenConfig>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_WhenConfigCopyWith<_$_WhenConfig> get copyWith => + __$$_WhenConfigCopyWithImpl<_$_WhenConfig>(this, _$identity); } abstract class _WhenConfig implements WhenConfig { factory _WhenConfig( - {required bool when, - required bool whenOrNull, - required bool maybeWhen}) = _$_WhenConfig; + {required final bool when, + required final bool whenOrNull, + required final bool maybeWhen}) = _$_WhenConfig; @override bool get when; @@ -1062,55 +1017,10 @@ abstract class _WhenConfig implements WhenConfig { bool get maybeWhen; @override @JsonKey(ignore: true) - _$WhenConfigCopyWith<_WhenConfig> get copyWith => + _$$_WhenConfigCopyWith<_$_WhenConfig> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$DataTearOff { - const _$DataTearOff(); - - _Data call( - {required String name, - required String unionKey, - required bool generateCopyWith, - required bool generateEqual, - required bool generateToString, - required MapConfig map, - required WhenConfig when, - required bool generateFromJson, - required bool generateToJson, - required bool makeCollectionsImmutable, - required List concretePropertiesName, - required List constructors, - required GenericsDefinitionTemplate genericsDefinitionTemplate, - required GenericsParameterTemplate genericsParameterTemplate, - required bool shouldUseExtends, - required bool genericArgumentFactories}) { - return _Data( - name: name, - unionKey: unionKey, - generateCopyWith: generateCopyWith, - generateEqual: generateEqual, - generateToString: generateToString, - map: map, - when: when, - generateFromJson: generateFromJson, - generateToJson: generateToJson, - makeCollectionsImmutable: makeCollectionsImmutable, - concretePropertiesName: concretePropertiesName, - constructors: constructors, - genericsDefinitionTemplate: genericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate, - shouldUseExtends: shouldUseExtends, - genericArgumentFactories: genericArgumentFactories, - ); - } -} - -/// @nodoc -const $Data = _$DataTearOff(); - /// @nodoc mixin _$Data { String get name => throw _privateConstructorUsedError; @@ -1140,7 +1050,8 @@ mixin _$Data { /// @nodoc abstract class $DataCopyWith<$Res> { factory $DataCopyWith(Data value, $Res Function(Data) then) = - _$DataCopyWithImpl<$Res>; + _$DataCopyWithImpl<$Res, Data>; + @useResult $Res call( {String name, String unionKey, @@ -1164,120 +1075,126 @@ abstract class $DataCopyWith<$Res> { } /// @nodoc -class _$DataCopyWithImpl<$Res> implements $DataCopyWith<$Res> { +class _$DataCopyWithImpl<$Res, $Val extends Data> + implements $DataCopyWith<$Res> { _$DataCopyWithImpl(this._value, this._then); - final Data _value; // ignore: unused_field - final $Res Function(Data) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionKey = freezed, - Object? generateCopyWith = freezed, - Object? generateEqual = freezed, - Object? generateToString = freezed, - Object? map = freezed, - Object? when = freezed, - Object? generateFromJson = freezed, - Object? generateToJson = freezed, - Object? makeCollectionsImmutable = freezed, - Object? concretePropertiesName = freezed, - Object? constructors = freezed, - Object? genericsDefinitionTemplate = freezed, - Object? genericsParameterTemplate = freezed, - Object? shouldUseExtends = freezed, - Object? genericArgumentFactories = freezed, + Object? name = null, + Object? unionKey = null, + Object? generateCopyWith = null, + Object? generateEqual = null, + Object? generateToString = null, + Object? map = null, + Object? when = null, + Object? generateFromJson = null, + Object? generateToJson = null, + Object? makeCollectionsImmutable = null, + Object? concretePropertiesName = null, + Object? constructors = null, + Object? genericsDefinitionTemplate = null, + Object? genericsParameterTemplate = null, + Object? shouldUseExtends = null, + Object? genericArgumentFactories = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionKey: unionKey == freezed + unionKey: null == unionKey ? _value.unionKey : unionKey // ignore: cast_nullable_to_non_nullable as String, - generateCopyWith: generateCopyWith == freezed + generateCopyWith: null == generateCopyWith ? _value.generateCopyWith : generateCopyWith // ignore: cast_nullable_to_non_nullable as bool, - generateEqual: generateEqual == freezed + generateEqual: null == generateEqual ? _value.generateEqual : generateEqual // ignore: cast_nullable_to_non_nullable as bool, - generateToString: generateToString == freezed + generateToString: null == generateToString ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as MapConfig, - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as WhenConfig, - generateFromJson: generateFromJson == freezed + generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable as bool, - generateToJson: generateToJson == freezed + generateToJson: null == generateToJson ? _value.generateToJson : generateToJson // ignore: cast_nullable_to_non_nullable as bool, - makeCollectionsImmutable: makeCollectionsImmutable == freezed + makeCollectionsImmutable: null == makeCollectionsImmutable ? _value.makeCollectionsImmutable : makeCollectionsImmutable // ignore: cast_nullable_to_non_nullable as bool, - concretePropertiesName: concretePropertiesName == freezed + concretePropertiesName: null == concretePropertiesName ? _value.concretePropertiesName : concretePropertiesName // ignore: cast_nullable_to_non_nullable as List, - constructors: constructors == freezed + constructors: null == constructors ? _value.constructors : constructors // ignore: cast_nullable_to_non_nullable as List, - genericsDefinitionTemplate: genericsDefinitionTemplate == freezed + genericsDefinitionTemplate: null == genericsDefinitionTemplate ? _value.genericsDefinitionTemplate : genericsDefinitionTemplate // ignore: cast_nullable_to_non_nullable as GenericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate == freezed + genericsParameterTemplate: null == genericsParameterTemplate ? _value.genericsParameterTemplate : genericsParameterTemplate // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - shouldUseExtends: shouldUseExtends == freezed + shouldUseExtends: null == shouldUseExtends ? _value.shouldUseExtends : shouldUseExtends // ignore: cast_nullable_to_non_nullable as bool, - genericArgumentFactories: genericArgumentFactories == freezed + genericArgumentFactories: null == genericArgumentFactories ? _value.genericArgumentFactories : genericArgumentFactories // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } @override + @pragma('vm:prefer-inline') $MapConfigCopyWith<$Res> get map { return $MapConfigCopyWith<$Res>(_value.map, (value) { - return _then(_value.copyWith(map: value)); + return _then(_value.copyWith(map: value) as $Val); }); } @override + @pragma('vm:prefer-inline') $WhenConfigCopyWith<$Res> get when { return $WhenConfigCopyWith<$Res>(_value.when, (value) { - return _then(_value.copyWith(when: value)); + return _then(_value.copyWith(when: value) as $Val); }); } } /// @nodoc -abstract class _$DataCopyWith<$Res> implements $DataCopyWith<$Res> { - factory _$DataCopyWith(_Data value, $Res Function(_Data) then) = - __$DataCopyWithImpl<$Res>; +abstract class _$$_DataCopyWith<$Res> implements $DataCopyWith<$Res> { + factory _$$_DataCopyWith(_$_Data value, $Res Function(_$_Data) then) = + __$$_DataCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String unionKey, @@ -1303,95 +1220,93 @@ abstract class _$DataCopyWith<$Res> implements $DataCopyWith<$Res> { } /// @nodoc -class __$DataCopyWithImpl<$Res> extends _$DataCopyWithImpl<$Res> - implements _$DataCopyWith<$Res> { - __$DataCopyWithImpl(_Data _value, $Res Function(_Data) _then) - : super(_value, (v) => _then(v as _Data)); - - @override - _Data get _value => super._value as _Data; +class __$$_DataCopyWithImpl<$Res> extends _$DataCopyWithImpl<$Res, _$_Data> + implements _$$_DataCopyWith<$Res> { + __$$_DataCopyWithImpl(_$_Data _value, $Res Function(_$_Data) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionKey = freezed, - Object? generateCopyWith = freezed, - Object? generateEqual = freezed, - Object? generateToString = freezed, - Object? map = freezed, - Object? when = freezed, - Object? generateFromJson = freezed, - Object? generateToJson = freezed, - Object? makeCollectionsImmutable = freezed, - Object? concretePropertiesName = freezed, - Object? constructors = freezed, - Object? genericsDefinitionTemplate = freezed, - Object? genericsParameterTemplate = freezed, - Object? shouldUseExtends = freezed, - Object? genericArgumentFactories = freezed, + Object? name = null, + Object? unionKey = null, + Object? generateCopyWith = null, + Object? generateEqual = null, + Object? generateToString = null, + Object? map = null, + Object? when = null, + Object? generateFromJson = null, + Object? generateToJson = null, + Object? makeCollectionsImmutable = null, + Object? concretePropertiesName = null, + Object? constructors = null, + Object? genericsDefinitionTemplate = null, + Object? genericsParameterTemplate = null, + Object? shouldUseExtends = null, + Object? genericArgumentFactories = null, }) { - return _then(_Data( - name: name == freezed + return _then(_$_Data( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionKey: unionKey == freezed + unionKey: null == unionKey ? _value.unionKey : unionKey // ignore: cast_nullable_to_non_nullable as String, - generateCopyWith: generateCopyWith == freezed + generateCopyWith: null == generateCopyWith ? _value.generateCopyWith : generateCopyWith // ignore: cast_nullable_to_non_nullable as bool, - generateEqual: generateEqual == freezed + generateEqual: null == generateEqual ? _value.generateEqual : generateEqual // ignore: cast_nullable_to_non_nullable as bool, - generateToString: generateToString == freezed + generateToString: null == generateToString ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as MapConfig, - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as WhenConfig, - generateFromJson: generateFromJson == freezed + generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable as bool, - generateToJson: generateToJson == freezed + generateToJson: null == generateToJson ? _value.generateToJson : generateToJson // ignore: cast_nullable_to_non_nullable as bool, - makeCollectionsImmutable: makeCollectionsImmutable == freezed + makeCollectionsImmutable: null == makeCollectionsImmutable ? _value.makeCollectionsImmutable : makeCollectionsImmutable // ignore: cast_nullable_to_non_nullable as bool, - concretePropertiesName: concretePropertiesName == freezed - ? _value.concretePropertiesName + concretePropertiesName: null == concretePropertiesName + ? _value._concretePropertiesName : concretePropertiesName // ignore: cast_nullable_to_non_nullable as List, - constructors: constructors == freezed - ? _value.constructors + constructors: null == constructors + ? _value._constructors : constructors // ignore: cast_nullable_to_non_nullable as List, - genericsDefinitionTemplate: genericsDefinitionTemplate == freezed + genericsDefinitionTemplate: null == genericsDefinitionTemplate ? _value.genericsDefinitionTemplate : genericsDefinitionTemplate // ignore: cast_nullable_to_non_nullable as GenericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate == freezed + genericsParameterTemplate: null == genericsParameterTemplate ? _value.genericsParameterTemplate : genericsParameterTemplate // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - shouldUseExtends: shouldUseExtends == freezed + shouldUseExtends: null == shouldUseExtends ? _value.shouldUseExtends : shouldUseExtends // ignore: cast_nullable_to_non_nullable as bool, - genericArgumentFactories: genericArgumentFactories == freezed + genericArgumentFactories: null == genericArgumentFactories ? _value.genericArgumentFactories : genericArgumentFactories // ignore: cast_nullable_to_non_nullable as bool, @@ -1413,13 +1328,15 @@ class _$_Data implements _Data { required this.generateFromJson, required this.generateToJson, required this.makeCollectionsImmutable, - required this.concretePropertiesName, - required this.constructors, + required final List concretePropertiesName, + required final List constructors, required this.genericsDefinitionTemplate, required this.genericsParameterTemplate, required this.shouldUseExtends, required this.genericArgumentFactories}) - : assert(constructors.isNotEmpty); + : assert(constructors.isNotEmpty), + _concretePropertiesName = concretePropertiesName, + _constructors = constructors; @override final String name; @@ -1441,10 +1358,20 @@ class _$_Data implements _Data { final bool generateToJson; @override final bool makeCollectionsImmutable; + final List _concretePropertiesName; @override - final List concretePropertiesName; + List get concretePropertiesName { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_concretePropertiesName); + } + + final List _constructors; @override - final List constructors; + List get constructors { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_constructors); + } + @override final GenericsDefinitionTemplate genericsDefinitionTemplate; @override @@ -1463,7 +1390,7 @@ class _$_Data implements _Data { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Data && + other is _$_Data && (identical(other.name, name) || other.name == name) && (identical(other.unionKey, unionKey) || other.unionKey == unionKey) && @@ -1482,10 +1409,10 @@ class _$_Data implements _Data { (identical( other.makeCollectionsImmutable, makeCollectionsImmutable) || other.makeCollectionsImmutable == makeCollectionsImmutable) && + const DeepCollectionEquality().equals( + other._concretePropertiesName, _concretePropertiesName) && const DeepCollectionEquality() - .equals(other.concretePropertiesName, concretePropertiesName) && - const DeepCollectionEquality() - .equals(other.constructors, constructors) && + .equals(other._constructors, _constructors) && (identical(other.genericsDefinitionTemplate, genericsDefinitionTemplate) || other.genericsDefinitionTemplate == @@ -1513,8 +1440,8 @@ class _$_Data implements _Data { generateFromJson, generateToJson, makeCollectionsImmutable, - const DeepCollectionEquality().hash(concretePropertiesName), - const DeepCollectionEquality().hash(constructors), + const DeepCollectionEquality().hash(_concretePropertiesName), + const DeepCollectionEquality().hash(_constructors), genericsDefinitionTemplate, genericsParameterTemplate, shouldUseExtends, @@ -1522,28 +1449,29 @@ class _$_Data implements _Data { @JsonKey(ignore: true) @override - _$DataCopyWith<_Data> get copyWith => - __$DataCopyWithImpl<_Data>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_DataCopyWith<_$_Data> get copyWith => + __$$_DataCopyWithImpl<_$_Data>(this, _$identity); } abstract class _Data implements Data { factory _Data( - {required String name, - required String unionKey, - required bool generateCopyWith, - required bool generateEqual, - required bool generateToString, - required MapConfig map, - required WhenConfig when, - required bool generateFromJson, - required bool generateToJson, - required bool makeCollectionsImmutable, - required List concretePropertiesName, - required List constructors, - required GenericsDefinitionTemplate genericsDefinitionTemplate, - required GenericsParameterTemplate genericsParameterTemplate, - required bool shouldUseExtends, - required bool genericArgumentFactories}) = _$_Data; + {required final String name, + required final String unionKey, + required final bool generateCopyWith, + required final bool generateEqual, + required final bool generateToString, + required final MapConfig map, + required final WhenConfig when, + required final bool generateFromJson, + required final bool generateToJson, + required final bool makeCollectionsImmutable, + required final List concretePropertiesName, + required final List constructors, + required final GenericsDefinitionTemplate genericsDefinitionTemplate, + required final GenericsParameterTemplate genericsParameterTemplate, + required final bool shouldUseExtends, + required final bool genericArgumentFactories}) = _$_Data; @override String get name; @@ -1579,24 +1507,9 @@ abstract class _Data implements Data { bool get genericArgumentFactories; @override @JsonKey(ignore: true) - _$DataCopyWith<_Data> get copyWith => throw _privateConstructorUsedError; + _$$_DataCopyWith<_$_Data> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$GlobalDataTearOff { - const _$GlobalDataTearOff(); - - _GlobalData call({required bool hasJson, required bool hasDiagnostics}) { - return _GlobalData( - hasJson: hasJson, - hasDiagnostics: hasDiagnostics, - ); - } -} - -/// @nodoc -const $GlobalData = _$GlobalDataTearOff(); - /// @nodoc mixin _$GlobalData { bool get hasJson => throw _privateConstructorUsedError; @@ -1611,66 +1524,71 @@ mixin _$GlobalData { abstract class $GlobalDataCopyWith<$Res> { factory $GlobalDataCopyWith( GlobalData value, $Res Function(GlobalData) then) = - _$GlobalDataCopyWithImpl<$Res>; + _$GlobalDataCopyWithImpl<$Res, GlobalData>; + @useResult $Res call({bool hasJson, bool hasDiagnostics}); } /// @nodoc -class _$GlobalDataCopyWithImpl<$Res> implements $GlobalDataCopyWith<$Res> { +class _$GlobalDataCopyWithImpl<$Res, $Val extends GlobalData> + implements $GlobalDataCopyWith<$Res> { _$GlobalDataCopyWithImpl(this._value, this._then); - final GlobalData _value; // ignore: unused_field - final $Res Function(GlobalData) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? hasJson = freezed, - Object? hasDiagnostics = freezed, + Object? hasJson = null, + Object? hasDiagnostics = null, }) { return _then(_value.copyWith( - hasJson: hasJson == freezed + hasJson: null == hasJson ? _value.hasJson : hasJson // ignore: cast_nullable_to_non_nullable as bool, - hasDiagnostics: hasDiagnostics == freezed + hasDiagnostics: null == hasDiagnostics ? _value.hasDiagnostics : hasDiagnostics // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$GlobalDataCopyWith<$Res> implements $GlobalDataCopyWith<$Res> { - factory _$GlobalDataCopyWith( - _GlobalData value, $Res Function(_GlobalData) then) = - __$GlobalDataCopyWithImpl<$Res>; +abstract class _$$_GlobalDataCopyWith<$Res> + implements $GlobalDataCopyWith<$Res> { + factory _$$_GlobalDataCopyWith( + _$_GlobalData value, $Res Function(_$_GlobalData) then) = + __$$_GlobalDataCopyWithImpl<$Res>; @override + @useResult $Res call({bool hasJson, bool hasDiagnostics}); } /// @nodoc -class __$GlobalDataCopyWithImpl<$Res> extends _$GlobalDataCopyWithImpl<$Res> - implements _$GlobalDataCopyWith<$Res> { - __$GlobalDataCopyWithImpl( - _GlobalData _value, $Res Function(_GlobalData) _then) - : super(_value, (v) => _then(v as _GlobalData)); - - @override - _GlobalData get _value => super._value as _GlobalData; +class __$$_GlobalDataCopyWithImpl<$Res> + extends _$GlobalDataCopyWithImpl<$Res, _$_GlobalData> + implements _$$_GlobalDataCopyWith<$Res> { + __$$_GlobalDataCopyWithImpl( + _$_GlobalData _value, $Res Function(_$_GlobalData) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? hasJson = freezed, - Object? hasDiagnostics = freezed, + Object? hasJson = null, + Object? hasDiagnostics = null, }) { - return _then(_GlobalData( - hasJson: hasJson == freezed + return _then(_$_GlobalData( + hasJson: null == hasJson ? _value.hasJson : hasJson // ignore: cast_nullable_to_non_nullable as bool, - hasDiagnostics: hasDiagnostics == freezed + hasDiagnostics: null == hasDiagnostics ? _value.hasDiagnostics : hasDiagnostics // ignore: cast_nullable_to_non_nullable as bool, @@ -1697,7 +1615,7 @@ class _$_GlobalData implements _GlobalData { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _GlobalData && + other is _$_GlobalData && (identical(other.hasJson, hasJson) || other.hasJson == hasJson) && (identical(other.hasDiagnostics, hasDiagnostics) || other.hasDiagnostics == hasDiagnostics)); @@ -1708,13 +1626,15 @@ class _$_GlobalData implements _GlobalData { @JsonKey(ignore: true) @override - _$GlobalDataCopyWith<_GlobalData> get copyWith => - __$GlobalDataCopyWithImpl<_GlobalData>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_GlobalDataCopyWith<_$_GlobalData> get copyWith => + __$$_GlobalDataCopyWithImpl<_$_GlobalData>(this, _$identity); } abstract class _GlobalData implements GlobalData { - factory _GlobalData({required bool hasJson, required bool hasDiagnostics}) = - _$_GlobalData; + factory _GlobalData( + {required final bool hasJson, + required final bool hasDiagnostics}) = _$_GlobalData; @override bool get hasJson; @@ -1722,6 +1642,6 @@ abstract class _GlobalData implements GlobalData { bool get hasDiagnostics; @override @JsonKey(ignore: true) - _$GlobalDataCopyWith<_GlobalData> get copyWith => + _$$_GlobalDataCopyWith<_$_GlobalData> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/_internal/pubspec.lock b/packages/_internal/pubspec.lock index 62f2e204..2ea6296a 100644 --- a/packages/_internal/pubspec.lock +++ b/packages/_internal/pubspec.lock @@ -5,386 +5,425 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - url: "https://pub.dartlang.org" + sha256: "3444216bfd127af50bbe4862d8843ed44db946dd933554f0d7285e89f10e28ac" + url: "https://pub.dev" source: hosted - version: "30.0.0" + version: "50.0.0" analyzer: dependency: transitive description: name: analyzer - url: "https://pub.dartlang.org" + sha256: "68796c31f510c8455a06fed75fc97d8e5ad04d324a830322ab3efc9feb6201c1" + url: "https://pub.dev" source: hosted - version: "2.7.0" + version: "5.2.0" args: dependency: transitive description: name: args - url: "https://pub.dartlang.org" + sha256: b003c3098049a51720352d219b0bb5f219b60fbfb68e7a4748139a06a5676515 + url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.3.1" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.10.0" build: dependency: transitive description: name: build - url: "https://pub.dartlang.org" + sha256: "3fbda25365741f8251b39f3917fb3c8e286a96fd068a5a242e11c2012d495777" + url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.3.1" build_config: dependency: transitive description: name: build_config - url: "https://pub.dartlang.org" + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.1.1" build_daemon: dependency: transitive description: name: build_daemon - url: "https://pub.dartlang.org" + sha256: "6bc5544ea6ce4428266e7ea680e945c68806c4aae2da0eb5e9ccf38df8d6acbf" + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.0" build_resolvers: dependency: transitive description: name: build_resolvers - url: "https://pub.dartlang.org" + sha256: "7c35a3a7868626257d8aee47b51c26b9dba11eaddf3431117ed2744951416aab" + url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.1.0" build_runner: dependency: "direct dev" description: name: build_runner - url: "https://pub.dartlang.org" + sha256: "6f48c61a9dcd2c3a9e62d3dcdab1ba382790e2f31026288cbabe55d6003c9c23" + url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.3.2" build_runner_core: dependency: transitive description: name: build_runner_core - url: "https://pub.dartlang.org" + sha256: "14febe0f5bac5ae474117a36099b4de6f1dbc52df6c5e55534b3da9591bf4292" + url: "https://pub.dev" source: hosted - version: "7.2.2" + version: "7.2.7" built_collection: dependency: transitive description: name: built_collection - url: "https://pub.dartlang.org" + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" source: hosted version: "5.1.1" built_value: dependency: transitive description: name: built_value - url: "https://pub.dartlang.org" - source: hosted - version: "8.1.3" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" + sha256: "59e08b0079bb75f7e27392498e26339387c1089c6bd58525a14eb8508637277b" + url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "8.4.2" checked_yaml: dependency: transitive description: name: checked_yaml - url: "https://pub.dartlang.org" + sha256: dd007e4fb8270916820a0d66e24f619266b60773cddd082c6439341645af2659 + url: "https://pub.dev" source: hosted version: "2.0.1" - cli_util: - dependency: transitive - description: - name: cli_util - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.5" code_builder: dependency: transitive description: name: code_builder - url: "https://pub.dartlang.org" + sha256: "02ce3596b459c666530f045ad6f96209474e8fee6e4855940a3cee65fb872ec5" + url: "https://pub.dev" source: hosted - version: "4.1.0" + version: "4.3.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.0" convert: dependency: transitive description: name: convert - url: "https://pub.dartlang.org" + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" dart_style: dependency: transitive description: name: dart_style - url: "https://pub.dartlang.org" + sha256: "7a03456c3490394c8e7665890333e91ae8a49be43542b616e414449ac358acd4" + url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.2.4" file: dependency: transitive description: name: file - url: "https://pub.dartlang.org" + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + url: "https://pub.dev" source: hosted - version: "6.1.2" + version: "6.1.4" fixnum: dependency: transitive description: name: fixnum - url: "https://pub.dartlang.org" + sha256: "04be3e934c52e082558cc9ee21f42f5c1cd7a1262f4c63cd0357c08d5bba81ec" + url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.0.1" freezed: dependency: "direct dev" description: name: freezed - url: "https://pub.dartlang.org" + sha256: "7070a65156b1d60b81649005843b9a6ec861db6903dec2db082c95473c8f5f72" + url: "https://pub.dev" source: hosted - version: "0.15.1+1" + version: "2.2.1" freezed_annotation: dependency: "direct main" description: name: freezed_annotation - url: "https://pub.dartlang.org" + sha256: aeac15850ef1b38ee368d4c53ba9a847e900bb2c53a4db3f6881cbb3cb684338 + url: "https://pub.dev" source: hosted - version: "0.15.0" + version: "2.2.0" frontend_server_client: dependency: transitive description: name: frontend_server_client - url: "https://pub.dartlang.org" + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "3.2.0" glob: dependency: transitive description: name: glob - url: "https://pub.dartlang.org" + sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" + url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.1.1" graphs: dependency: transitive description: name: graphs - url: "https://pub.dartlang.org" + sha256: f9e130f3259f52d26f0cfc0e964513796dafed572fa52e45d2f8d6ca14db39b2 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.2.0" http_multi_server: dependency: transitive description: name: http_multi_server - url: "https://pub.dartlang.org" + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.2.1" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.2" io: dependency: transitive description: name: io - url: "https://pub.dartlang.org" + sha256: "0d4c73c3653ab85bf696d51a9657604c900a370549196a91f33e4c39af760852" + url: "https://pub.dev" source: hosted version: "1.0.3" js: dependency: transitive description: name: js - url: "https://pub.dartlang.org" + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" source: hosted - version: "0.6.3" + version: "0.6.5" json_annotation: dependency: transitive description: name: json_annotation - url: "https://pub.dartlang.org" + sha256: "3520fa844009431b5d4491a5a778603520cdc399ab3406332dcc50f93547258c" + url: "https://pub.dev" source: hosted - version: "4.3.0" + version: "4.7.0" logging: dependency: transitive description: name: logging - url: "https://pub.dartlang.org" + sha256: c0bbfe94d46aedf9b8b3e695cf3bd48c8e14b35e3b2c639e0aa7755d589ba946 + url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.1.0" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.13" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: name: mime - url: "https://pub.dartlang.org" + sha256: "52e38f7e1143ef39daf532117d6b8f8f617bf4bcd6044ed8c29040d20d269630" + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.0.3" package_config: dependency: transitive description: name: package_config - url: "https://pub.dartlang.org" + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.1.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.2" pool: dependency: transitive description: name: pool - url: "https://pub.dartlang.org" + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" source: hosted - version: "1.5.0" + version: "1.5.1" pub_semver: dependency: transitive description: name: pub_semver - url: "https://pub.dartlang.org" + sha256: "307de764d305289ff24ad257ad5c5793ce56d04947599ad68b3baa124105fc17" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.3" pubspec_parse: dependency: transitive description: name: pubspec_parse - url: "https://pub.dartlang.org" + sha256: "75f6614d6dde2dc68948dffbaa4fe5dae32cd700eb9fb763fe11dfb45a3c4d0a" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.1" shelf: dependency: transitive description: name: shelf - url: "https://pub.dartlang.org" + sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.4.0" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - url: "https://pub.dartlang.org" + sha256: a988c0e8d8ffbdb8a28aa7ec8e449c260f3deb808781fe1284d22c5bba7156e8 + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.0.3" source_gen: dependency: transitive description: name: source_gen - url: "https://pub.dartlang.org" + sha256: "2d79738b6bbf38a43920e2b8d189e9a3ce6cc201f4b8fc76be5e4fe377b1c38d" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.6" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" stream_transform: dependency: transitive description: name: stream_transform - url: "https://pub.dartlang.org" + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" timing: dependency: transitive description: name: timing - url: "https://pub.dartlang.org" + sha256: c386d07d7f5efc613479a7c4d9d64b03710b03cfaa7e8ad5f2bfb295a1f0dfad + url: "https://pub.dev" source: hosted version: "1.0.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" watcher: dependency: transitive description: name: watcher - url: "https://pub.dartlang.org" + sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0" + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.0.2" web_socket_channel: dependency: transitive description: name: web_socket_channel - url: "https://pub.dartlang.org" + sha256: "3a969ddcc204a3e34e863d204b29c0752716f78b6f9cc8235083208d268a4ccd" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.2.0" yaml: dependency: transitive description: name: yaml - url: "https://pub.dartlang.org" + sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" + url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.1" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.18.0 <4.0.0" diff --git a/packages/_internal/pubspec.yaml b/packages/_internal/pubspec.yaml index 0116dda3..a28de47c 100644 --- a/packages/_internal/pubspec.yaml +++ b/packages/_internal/pubspec.yaml @@ -5,8 +5,8 @@ environment: sdk: ">=2.14.0 <3.0.0" dependencies: - freezed_annotation: ">=0.14.0" + freezed_annotation: ^2.0.0 dev_dependencies: build_runner: - freezed: ^0.15.0+1 + freezed: ^2.0.0 diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index e2a4016a..e3ece343 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -43,6 +43,14 @@ extension on DartObject { } } +class CommonProperties { + /// Properties that have a getter in the abstract class + final List readableProperties = []; + + /// Properties that are visible on `copyWith` + final List cloneableProperties = []; +} + @immutable class FreezedGenerator extends ParserGenerator { FreezedGenerator(this._buildYamlConfigs); @@ -125,14 +133,6 @@ class FreezedGenerator extends ParserGenerator { ); } - List _commonProperties( - List constructorsNeedsGeneration, - ) { - return _commonParametersBetweenAllConstructors(constructorsNeedsGeneration) - .map(Property.fromParameter) - .toList(); - } - void _assertValidClassUsage(ClassElement element) { // TODO: verify _$name is mixed-in if (element.isAbstract) { @@ -229,50 +229,77 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C return false; } - List _commonParametersBetweenAllConstructors( + CommonProperties _commonParametersBetweenAllConstructors( List constructorsNeedsGeneration, ) { - return constructorsNeedsGeneration.first.parameters.allParameters - .map((parameter) { - final library = parameter.parameterElement!.library!; - - var anyMatchingPropertyIsFinal = parameter.isFinal; - var commonTypeBetweenAllUnionConstructors = - parameter.parameterElement!.type; - - // skip(1) as "parameter" is from the first constructor. - for (final constructor in constructorsNeedsGeneration.skip(1)) { - final matchingParameter = constructor.parameters.allParameters - .firstWhereOrNull((p) => p.name == parameter.name); - // The property is not present in one of the union cases, so shouldn't - // be present in the abstract class. - if (matchingParameter == null) return null; - anyMatchingPropertyIsFinal = - anyMatchingPropertyIsFinal || matchingParameter.isFinal; - - commonTypeBetweenAllUnionConstructors = - library.typeSystem.leastUpperBound( - commonTypeBetweenAllUnionConstructors, - matchingParameter.parameterElement!.type, - ); - } - - final commonTypeString = resolveFullTypeStringFrom( - library, - commonTypeBetweenAllUnionConstructors, - withNullability: true, - ); + final result = CommonProperties(); + if (constructorsNeedsGeneration.length == 1) { + result.readableProperties.addAll( + constructorsNeedsGeneration.first.parameters.allParameters + .map(Property.fromParameter), + ); + result.cloneableProperties.addAll(result.readableProperties); + return result; + } - return parameter.copyWith( - isFinal: anyMatchingPropertyIsFinal || - // The field was downcasted because some union cases use a - // different type for that field. As such, there is no valid setter - parameter.type != commonTypeString, - type: commonTypeString, - ); - }) - .whereNotNull() - .toList(); + parameterLoop: + for (final parameter + in constructorsNeedsGeneration.first.parameters.allParameters) { + final library = parameter.parameterElement!.library!; + + var anyMatchingPropertyIsFinal = parameter.isFinal; + var commonTypeBetweenAllUnionConstructors = + parameter.parameterElement!.type; + + // skip(1) as "parameter" is from the first constructor. + for (final constructor in constructorsNeedsGeneration) { + final matchingParameter = constructor.parameters.allParameters + .firstWhereOrNull((p) => p.name == parameter.name); + // The property is not present in one of the union cases, so shouldn't + // be present in the abstract class. + if (matchingParameter == null) continue parameterLoop; + + anyMatchingPropertyIsFinal = + anyMatchingPropertyIsFinal || matchingParameter.isFinal; + + commonTypeBetweenAllUnionConstructors = + library.typeSystem.leastUpperBound( + commonTypeBetweenAllUnionConstructors, + matchingParameter.parameterElement!.type, + ); + } + + final commonTypeString = resolveFullTypeStringFrom( + library, + commonTypeBetweenAllUnionConstructors, + withNullability: true, + ); + + final commonProperty = Property.fromParameter(parameter).copyWith( + isFinal: anyMatchingPropertyIsFinal || + // The field was downcasted because some union cases use a + // different type for that field. As such, there is no valid setter + parameter.type != commonTypeString, + type: commonTypeString, + ); + + result.readableProperties.add(commonProperty); + + // For {int a, int b, int c} | {int a, int? b, double c}, allows: + // copyWith({int a, int b}) + // - int? b is not allowed because `null` is not compatible with the + // first union case. + // - num c is not allowed because num is not assignable int/double + if (parameter.type == commonProperty.type || + '${parameter.type}?' == commonProperty.type) { + result.cloneableProperties.add( + // Let's not downcast copyWith parameters + commonProperty.copyWith(type: parameter.type), + ); + } + } + + return result; } Future> _parseConstructorsNeedsGeneration( @@ -339,7 +366,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C isDefault: isDefaultConstructor(constructor), hasJsonSerializable: constructor.hasJsonSerializable, isFallback: constructor.isFallbackUnion(options.fallbackUnion), - cloneableProperties: await _cloneableProperties( + cloneableProperties: _cloneableProperties( buildStep, element, constructor, @@ -416,11 +443,11 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } } - Stream _cloneableProperties( + Iterable _cloneableProperties( BuildStep buildStep, ClassElement element, ConstructorElement constructor, - ) async* { + ) sync* { for (final parameter in constructor.parameters) { final type = parseTypeSource(parameter); @@ -438,7 +465,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C // copyWith not enabled, so the property is not cloneable if (configs.copyWith != true) continue; - yield CloneableProperty( + yield DeepCloneableProperty( name: parameter.name, type: type!, nullable: @@ -454,7 +481,7 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C } } - Iterable _commonCloneableProperties( + Iterable _getCommonDeepCloneableProperties( List constructors, List commonProperties, ) sync* { @@ -611,44 +638,45 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C ); } - final commonProperties = _commonProperties(data.constructors); - final commonCopyableProperties = - commonProperties.where((p) => p.isDowncastedAsCommonProperty).toList(); + final commonProperties = + _commonParametersBetweenAllConstructors(data.constructors); final commonCopyWith = !data.generateCopyWith ? null : CopyWith( clonedClassName: data.name, - cloneableProperties: _commonCloneableProperties( + readableProperties: commonProperties.readableProperties, + cloneableProperties: commonProperties.cloneableProperties, + deepCloneableProperties: _getCommonDeepCloneableProperties( data.constructors, - commonCopyableProperties, + commonProperties.cloneableProperties, ).toList(), genericsDefinition: data.genericsDefinitionTemplate, genericsParameter: data.genericsParameterTemplate, - allProperties: commonCopyableProperties, data: data, ); yield Abstract( data: data, copyWith: commonCopyWith, - commonProperties: commonProperties, + commonProperties: commonProperties.readableProperties, ); for (final constructor in data.constructors) { yield Concrete( data: data, constructor: constructor, - commonProperties: commonProperties, + commonProperties: commonProperties.readableProperties, globalData: globalData, copyWith: !data.generateCopyWith ? null : CopyWith( clonedClassName: '_\$${constructor.redirectedName}', - cloneableProperties: constructor.cloneableProperties, + cloneableProperties: constructor.impliedProperties, + readableProperties: constructor.impliedProperties, + deepCloneableProperties: constructor.cloneableProperties, genericsDefinition: data.genericsDefinitionTemplate, genericsParameter: data.genericsParameterTemplate, - allProperties: constructor.impliedProperties, data: data, parent: commonCopyWith, ), diff --git a/packages/freezed/lib/src/models.dart b/packages/freezed/lib/src/models.dart index 0f2e42e4..26a8ea58 100644 --- a/packages/freezed/lib/src/models.dart +++ b/packages/freezed/lib/src/models.dart @@ -15,14 +15,14 @@ part 'models.freezed.dart'; /// This allows Freezed to support deep copy of the object. /// This does include primitives like [int] and [List]. @freezed -class CloneableProperty with _$CloneableProperty { - factory CloneableProperty({ +class DeepCloneableProperty with _$DeepCloneableProperty { + factory DeepCloneableProperty({ required String name, required String typeName, required String type, required bool nullable, required GenericsParameterTemplate genericParameters, - }) = _CloneableProperty; + }) = _DeepCloneableProperty; } /// The information of a specific constructor of a class tagged with `@freezed`. @@ -45,7 +45,7 @@ class ConstructorDetails with _$ConstructorDetails { required List withDecorators, required List implementsDecorators, required List decorators, - required List cloneableProperties, + required List cloneableProperties, required List asserts, }) = _ConstructorDetails; diff --git a/packages/freezed/lib/src/models.freezed.dart b/packages/freezed/lib/src/models.freezed.dart index 85eb285a..e182134d 100644 --- a/packages/freezed/lib/src/models.freezed.dart +++ b/packages/freezed/lib/src/models.freezed.dart @@ -1,5 +1,6 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target part of 'models.dart'; @@ -14,30 +15,7 @@ final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); /// @nodoc -class _$CloneablePropertyTearOff { - const _$CloneablePropertyTearOff(); - - _CloneableProperty call( - {required String name, - required String typeName, - required String type, - required bool nullable, - required GenericsParameterTemplate genericParameters}) { - return _CloneableProperty( - name: name, - typeName: typeName, - type: type, - nullable: nullable, - genericParameters: genericParameters, - ); - } -} - -/// @nodoc -const $CloneableProperty = _$CloneablePropertyTearOff(); - -/// @nodoc -mixin _$CloneableProperty { +mixin _$DeepCloneableProperty { String get name => throw _privateConstructorUsedError; String get typeName => throw _privateConstructorUsedError; String get type => throw _privateConstructorUsedError; @@ -46,15 +24,16 @@ mixin _$CloneableProperty { throw _privateConstructorUsedError; @JsonKey(ignore: true) - $CloneablePropertyCopyWith get copyWith => + $DeepCloneablePropertyCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $CloneablePropertyCopyWith<$Res> { - factory $CloneablePropertyCopyWith( - CloneableProperty value, $Res Function(CloneableProperty) then) = - _$CloneablePropertyCopyWithImpl<$Res>; +abstract class $DeepCloneablePropertyCopyWith<$Res> { + factory $DeepCloneablePropertyCopyWith(DeepCloneableProperty value, + $Res Function(DeepCloneableProperty) then) = + _$DeepCloneablePropertyCopyWithImpl<$Res, DeepCloneableProperty>; + @useResult $Res call( {String name, String typeName, @@ -64,54 +43,58 @@ abstract class $CloneablePropertyCopyWith<$Res> { } /// @nodoc -class _$CloneablePropertyCopyWithImpl<$Res> - implements $CloneablePropertyCopyWith<$Res> { - _$CloneablePropertyCopyWithImpl(this._value, this._then); +class _$DeepCloneablePropertyCopyWithImpl<$Res, + $Val extends DeepCloneableProperty> + implements $DeepCloneablePropertyCopyWith<$Res> { + _$DeepCloneablePropertyCopyWithImpl(this._value, this._then); - final CloneableProperty _value; // ignore: unused_field - final $Res Function(CloneableProperty) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? typeName = freezed, - Object? type = freezed, - Object? nullable = freezed, - Object? genericParameters = freezed, + Object? name = null, + Object? typeName = null, + Object? type = null, + Object? nullable = null, + Object? genericParameters = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - typeName: typeName == freezed + typeName: null == typeName ? _value.typeName : typeName // ignore: cast_nullable_to_non_nullable as String, - type: type == freezed + type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - nullable: nullable == freezed + nullable: null == nullable ? _value.nullable : nullable // ignore: cast_nullable_to_non_nullable as bool, - genericParameters: genericParameters == freezed + genericParameters: null == genericParameters ? _value.genericParameters : genericParameters // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - )); + ) as $Val); } } /// @nodoc -abstract class _$CloneablePropertyCopyWith<$Res> - implements $CloneablePropertyCopyWith<$Res> { - factory _$CloneablePropertyCopyWith( - _CloneableProperty value, $Res Function(_CloneableProperty) then) = - __$CloneablePropertyCopyWithImpl<$Res>; +abstract class _$$_DeepCloneablePropertyCopyWith<$Res> + implements $DeepCloneablePropertyCopyWith<$Res> { + factory _$$_DeepCloneablePropertyCopyWith(_$_DeepCloneableProperty value, + $Res Function(_$_DeepCloneableProperty) then) = + __$$_DeepCloneablePropertyCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String typeName, @@ -121,42 +104,40 @@ abstract class _$CloneablePropertyCopyWith<$Res> } /// @nodoc -class __$CloneablePropertyCopyWithImpl<$Res> - extends _$CloneablePropertyCopyWithImpl<$Res> - implements _$CloneablePropertyCopyWith<$Res> { - __$CloneablePropertyCopyWithImpl( - _CloneableProperty _value, $Res Function(_CloneableProperty) _then) - : super(_value, (v) => _then(v as _CloneableProperty)); - - @override - _CloneableProperty get _value => super._value as _CloneableProperty; +class __$$_DeepCloneablePropertyCopyWithImpl<$Res> + extends _$DeepCloneablePropertyCopyWithImpl<$Res, _$_DeepCloneableProperty> + implements _$$_DeepCloneablePropertyCopyWith<$Res> { + __$$_DeepCloneablePropertyCopyWithImpl(_$_DeepCloneableProperty _value, + $Res Function(_$_DeepCloneableProperty) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? typeName = freezed, - Object? type = freezed, - Object? nullable = freezed, - Object? genericParameters = freezed, + Object? name = null, + Object? typeName = null, + Object? type = null, + Object? nullable = null, + Object? genericParameters = null, }) { - return _then(_CloneableProperty( - name: name == freezed + return _then(_$_DeepCloneableProperty( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - typeName: typeName == freezed + typeName: null == typeName ? _value.typeName : typeName // ignore: cast_nullable_to_non_nullable as String, - type: type == freezed + type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - nullable: nullable == freezed + nullable: null == nullable ? _value.nullable : nullable // ignore: cast_nullable_to_non_nullable as bool, - genericParameters: genericParameters == freezed + genericParameters: null == genericParameters ? _value.genericParameters : genericParameters // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, @@ -166,8 +147,8 @@ class __$CloneablePropertyCopyWithImpl<$Res> /// @nodoc -class _$_CloneableProperty implements _CloneableProperty { - _$_CloneableProperty( +class _$_DeepCloneableProperty implements _DeepCloneableProperty { + _$_DeepCloneableProperty( {required this.name, required this.typeName, required this.type, @@ -187,14 +168,14 @@ class _$_CloneableProperty implements _CloneableProperty { @override String toString() { - return 'CloneableProperty(name: $name, typeName: $typeName, type: $type, nullable: $nullable, genericParameters: $genericParameters)'; + return 'DeepCloneableProperty(name: $name, typeName: $typeName, type: $type, nullable: $nullable, genericParameters: $genericParameters)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _CloneableProperty && + other is _$_DeepCloneableProperty && (identical(other.name, name) || other.name == name) && (identical(other.typeName, typeName) || other.typeName == typeName) && @@ -211,18 +192,20 @@ class _$_CloneableProperty implements _CloneableProperty { @JsonKey(ignore: true) @override - _$CloneablePropertyCopyWith<_CloneableProperty> get copyWith => - __$CloneablePropertyCopyWithImpl<_CloneableProperty>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_DeepCloneablePropertyCopyWith<_$_DeepCloneableProperty> get copyWith => + __$$_DeepCloneablePropertyCopyWithImpl<_$_DeepCloneableProperty>( + this, _$identity); } -abstract class _CloneableProperty implements CloneableProperty { - factory _CloneableProperty( - {required String name, - required String typeName, - required String type, - required bool nullable, - required GenericsParameterTemplate genericParameters}) = - _$_CloneableProperty; +abstract class _DeepCloneableProperty implements DeepCloneableProperty { + factory _DeepCloneableProperty( + {required final String name, + required final String typeName, + required final String type, + required final bool nullable, + required final GenericsParameterTemplate genericParameters}) = + _$_DeepCloneableProperty; @override String get name; @@ -236,55 +219,10 @@ abstract class _CloneableProperty implements CloneableProperty { GenericsParameterTemplate get genericParameters; @override @JsonKey(ignore: true) - _$CloneablePropertyCopyWith<_CloneableProperty> get copyWith => + _$$_DeepCloneablePropertyCopyWith<_$_DeepCloneableProperty> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$ConstructorDetailsTearOff { - const _$ConstructorDetailsTearOff(); - - _ConstructorDetails call( - {required String name, - required String unionValue, - required bool isConst, - required String redirectedName, - required ParametersTemplate parameters, - required List impliedProperties, - required bool isDefault, - required bool isFallback, - required bool hasJsonSerializable, - required String fullName, - required String escapedName, - required List withDecorators, - required List implementsDecorators, - required List decorators, - required List cloneableProperties, - required List asserts}) { - return _ConstructorDetails( - name: name, - unionValue: unionValue, - isConst: isConst, - redirectedName: redirectedName, - parameters: parameters, - impliedProperties: impliedProperties, - isDefault: isDefault, - isFallback: isFallback, - hasJsonSerializable: hasJsonSerializable, - fullName: fullName, - escapedName: escapedName, - withDecorators: withDecorators, - implementsDecorators: implementsDecorators, - decorators: decorators, - cloneableProperties: cloneableProperties, - asserts: asserts, - ); - } -} - -/// @nodoc -const $ConstructorDetails = _$ConstructorDetailsTearOff(); - /// @nodoc mixin _$ConstructorDetails { String get name => throw _privateConstructorUsedError; @@ -301,7 +239,7 @@ mixin _$ConstructorDetails { List get withDecorators => throw _privateConstructorUsedError; List get implementsDecorators => throw _privateConstructorUsedError; List get decorators => throw _privateConstructorUsedError; - List get cloneableProperties => + List get cloneableProperties => throw _privateConstructorUsedError; List get asserts => throw _privateConstructorUsedError; @@ -314,7 +252,8 @@ mixin _$ConstructorDetails { abstract class $ConstructorDetailsCopyWith<$Res> { factory $ConstructorDetailsCopyWith( ConstructorDetails value, $Res Function(ConstructorDetails) then) = - _$ConstructorDetailsCopyWithImpl<$Res>; + _$ConstructorDetailsCopyWithImpl<$Res, ConstructorDetails>; + @useResult $Res call( {String name, String unionValue, @@ -330,114 +269,117 @@ abstract class $ConstructorDetailsCopyWith<$Res> { List withDecorators, List implementsDecorators, List decorators, - List cloneableProperties, + List cloneableProperties, List asserts}); } /// @nodoc -class _$ConstructorDetailsCopyWithImpl<$Res> +class _$ConstructorDetailsCopyWithImpl<$Res, $Val extends ConstructorDetails> implements $ConstructorDetailsCopyWith<$Res> { _$ConstructorDetailsCopyWithImpl(this._value, this._then); - final ConstructorDetails _value; // ignore: unused_field - final $Res Function(ConstructorDetails) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionValue = freezed, - Object? isConst = freezed, - Object? redirectedName = freezed, - Object? parameters = freezed, - Object? impliedProperties = freezed, - Object? isDefault = freezed, - Object? isFallback = freezed, - Object? hasJsonSerializable = freezed, - Object? fullName = freezed, - Object? escapedName = freezed, - Object? withDecorators = freezed, - Object? implementsDecorators = freezed, - Object? decorators = freezed, - Object? cloneableProperties = freezed, - Object? asserts = freezed, + Object? name = null, + Object? unionValue = null, + Object? isConst = null, + Object? redirectedName = null, + Object? parameters = null, + Object? impliedProperties = null, + Object? isDefault = null, + Object? isFallback = null, + Object? hasJsonSerializable = null, + Object? fullName = null, + Object? escapedName = null, + Object? withDecorators = null, + Object? implementsDecorators = null, + Object? decorators = null, + Object? cloneableProperties = null, + Object? asserts = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionValue: unionValue == freezed + unionValue: null == unionValue ? _value.unionValue : unionValue // ignore: cast_nullable_to_non_nullable as String, - isConst: isConst == freezed + isConst: null == isConst ? _value.isConst : isConst // ignore: cast_nullable_to_non_nullable as bool, - redirectedName: redirectedName == freezed + redirectedName: null == redirectedName ? _value.redirectedName : redirectedName // ignore: cast_nullable_to_non_nullable as String, - parameters: parameters == freezed + parameters: null == parameters ? _value.parameters : parameters // ignore: cast_nullable_to_non_nullable as ParametersTemplate, - impliedProperties: impliedProperties == freezed + impliedProperties: null == impliedProperties ? _value.impliedProperties : impliedProperties // ignore: cast_nullable_to_non_nullable as List, - isDefault: isDefault == freezed + isDefault: null == isDefault ? _value.isDefault : isDefault // ignore: cast_nullable_to_non_nullable as bool, - isFallback: isFallback == freezed + isFallback: null == isFallback ? _value.isFallback : isFallback // ignore: cast_nullable_to_non_nullable as bool, - hasJsonSerializable: hasJsonSerializable == freezed + hasJsonSerializable: null == hasJsonSerializable ? _value.hasJsonSerializable : hasJsonSerializable // ignore: cast_nullable_to_non_nullable as bool, - fullName: fullName == freezed + fullName: null == fullName ? _value.fullName : fullName // ignore: cast_nullable_to_non_nullable as String, - escapedName: escapedName == freezed + escapedName: null == escapedName ? _value.escapedName : escapedName // ignore: cast_nullable_to_non_nullable as String, - withDecorators: withDecorators == freezed + withDecorators: null == withDecorators ? _value.withDecorators : withDecorators // ignore: cast_nullable_to_non_nullable as List, - implementsDecorators: implementsDecorators == freezed + implementsDecorators: null == implementsDecorators ? _value.implementsDecorators : implementsDecorators // ignore: cast_nullable_to_non_nullable as List, - decorators: decorators == freezed + decorators: null == decorators ? _value.decorators : decorators // ignore: cast_nullable_to_non_nullable as List, - cloneableProperties: cloneableProperties == freezed + cloneableProperties: null == cloneableProperties ? _value.cloneableProperties : cloneableProperties // ignore: cast_nullable_to_non_nullable - as List, - asserts: asserts == freezed + as List, + asserts: null == asserts ? _value.asserts : asserts // ignore: cast_nullable_to_non_nullable as List, - )); + ) as $Val); } } /// @nodoc -abstract class _$ConstructorDetailsCopyWith<$Res> +abstract class _$$_ConstructorDetailsCopyWith<$Res> implements $ConstructorDetailsCopyWith<$Res> { - factory _$ConstructorDetailsCopyWith( - _ConstructorDetails value, $Res Function(_ConstructorDetails) then) = - __$ConstructorDetailsCopyWithImpl<$Res>; + factory _$$_ConstructorDetailsCopyWith(_$_ConstructorDetails value, + $Res Function(_$_ConstructorDetails) then) = + __$$_ConstructorDetailsCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String unionValue, @@ -453,103 +395,101 @@ abstract class _$ConstructorDetailsCopyWith<$Res> List withDecorators, List implementsDecorators, List decorators, - List cloneableProperties, + List cloneableProperties, List asserts}); } /// @nodoc -class __$ConstructorDetailsCopyWithImpl<$Res> - extends _$ConstructorDetailsCopyWithImpl<$Res> - implements _$ConstructorDetailsCopyWith<$Res> { - __$ConstructorDetailsCopyWithImpl( - _ConstructorDetails _value, $Res Function(_ConstructorDetails) _then) - : super(_value, (v) => _then(v as _ConstructorDetails)); - - @override - _ConstructorDetails get _value => super._value as _ConstructorDetails; +class __$$_ConstructorDetailsCopyWithImpl<$Res> + extends _$ConstructorDetailsCopyWithImpl<$Res, _$_ConstructorDetails> + implements _$$_ConstructorDetailsCopyWith<$Res> { + __$$_ConstructorDetailsCopyWithImpl( + _$_ConstructorDetails _value, $Res Function(_$_ConstructorDetails) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionValue = freezed, - Object? isConst = freezed, - Object? redirectedName = freezed, - Object? parameters = freezed, - Object? impliedProperties = freezed, - Object? isDefault = freezed, - Object? isFallback = freezed, - Object? hasJsonSerializable = freezed, - Object? fullName = freezed, - Object? escapedName = freezed, - Object? withDecorators = freezed, - Object? implementsDecorators = freezed, - Object? decorators = freezed, - Object? cloneableProperties = freezed, - Object? asserts = freezed, + Object? name = null, + Object? unionValue = null, + Object? isConst = null, + Object? redirectedName = null, + Object? parameters = null, + Object? impliedProperties = null, + Object? isDefault = null, + Object? isFallback = null, + Object? hasJsonSerializable = null, + Object? fullName = null, + Object? escapedName = null, + Object? withDecorators = null, + Object? implementsDecorators = null, + Object? decorators = null, + Object? cloneableProperties = null, + Object? asserts = null, }) { - return _then(_ConstructorDetails( - name: name == freezed + return _then(_$_ConstructorDetails( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionValue: unionValue == freezed + unionValue: null == unionValue ? _value.unionValue : unionValue // ignore: cast_nullable_to_non_nullable as String, - isConst: isConst == freezed + isConst: null == isConst ? _value.isConst : isConst // ignore: cast_nullable_to_non_nullable as bool, - redirectedName: redirectedName == freezed + redirectedName: null == redirectedName ? _value.redirectedName : redirectedName // ignore: cast_nullable_to_non_nullable as String, - parameters: parameters == freezed + parameters: null == parameters ? _value.parameters : parameters // ignore: cast_nullable_to_non_nullable as ParametersTemplate, - impliedProperties: impliedProperties == freezed - ? _value.impliedProperties + impliedProperties: null == impliedProperties + ? _value._impliedProperties : impliedProperties // ignore: cast_nullable_to_non_nullable as List, - isDefault: isDefault == freezed + isDefault: null == isDefault ? _value.isDefault : isDefault // ignore: cast_nullable_to_non_nullable as bool, - isFallback: isFallback == freezed + isFallback: null == isFallback ? _value.isFallback : isFallback // ignore: cast_nullable_to_non_nullable as bool, - hasJsonSerializable: hasJsonSerializable == freezed + hasJsonSerializable: null == hasJsonSerializable ? _value.hasJsonSerializable : hasJsonSerializable // ignore: cast_nullable_to_non_nullable as bool, - fullName: fullName == freezed + fullName: null == fullName ? _value.fullName : fullName // ignore: cast_nullable_to_non_nullable as String, - escapedName: escapedName == freezed + escapedName: null == escapedName ? _value.escapedName : escapedName // ignore: cast_nullable_to_non_nullable as String, - withDecorators: withDecorators == freezed - ? _value.withDecorators + withDecorators: null == withDecorators + ? _value._withDecorators : withDecorators // ignore: cast_nullable_to_non_nullable as List, - implementsDecorators: implementsDecorators == freezed - ? _value.implementsDecorators + implementsDecorators: null == implementsDecorators + ? _value._implementsDecorators : implementsDecorators // ignore: cast_nullable_to_non_nullable as List, - decorators: decorators == freezed - ? _value.decorators + decorators: null == decorators + ? _value._decorators : decorators // ignore: cast_nullable_to_non_nullable as List, - cloneableProperties: cloneableProperties == freezed - ? _value.cloneableProperties + cloneableProperties: null == cloneableProperties + ? _value._cloneableProperties : cloneableProperties // ignore: cast_nullable_to_non_nullable - as List, - asserts: asserts == freezed - ? _value.asserts + as List, + asserts: null == asserts + ? _value._asserts : asserts // ignore: cast_nullable_to_non_nullable as List, )); @@ -565,18 +505,24 @@ class _$_ConstructorDetails extends _ConstructorDetails { required this.isConst, required this.redirectedName, required this.parameters, - required this.impliedProperties, + required final List impliedProperties, required this.isDefault, required this.isFallback, required this.hasJsonSerializable, required this.fullName, required this.escapedName, - required this.withDecorators, - required this.implementsDecorators, - required this.decorators, - required this.cloneableProperties, - required this.asserts}) - : super._(); + required final List withDecorators, + required final List implementsDecorators, + required final List decorators, + required final List cloneableProperties, + required final List asserts}) + : _impliedProperties = impliedProperties, + _withDecorators = withDecorators, + _implementsDecorators = implementsDecorators, + _decorators = decorators, + _cloneableProperties = cloneableProperties, + _asserts = asserts, + super._(); @override final String name; @@ -588,8 +534,13 @@ class _$_ConstructorDetails extends _ConstructorDetails { final String redirectedName; @override final ParametersTemplate parameters; + final List _impliedProperties; @override - final List impliedProperties; + List get impliedProperties { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_impliedProperties); + } + @override final bool isDefault; @override @@ -600,16 +551,40 @@ class _$_ConstructorDetails extends _ConstructorDetails { final String fullName; @override final String escapedName; + final List _withDecorators; @override - final List withDecorators; + List get withDecorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_withDecorators); + } + + final List _implementsDecorators; @override - final List implementsDecorators; + List get implementsDecorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_implementsDecorators); + } + + final List _decorators; @override - final List decorators; + List get decorators { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_decorators); + } + + final List _cloneableProperties; @override - final List cloneableProperties; + List get cloneableProperties { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_cloneableProperties); + } + + final List _asserts; @override - final List asserts; + List get asserts { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_asserts); + } @override String toString() { @@ -620,7 +595,7 @@ class _$_ConstructorDetails extends _ConstructorDetails { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _ConstructorDetails && + other is _$_ConstructorDetails && (identical(other.name, name) || other.name == name) && (identical(other.unionValue, unionValue) || other.unionValue == unionValue) && @@ -630,7 +605,7 @@ class _$_ConstructorDetails extends _ConstructorDetails { (identical(other.parameters, parameters) || other.parameters == parameters) && const DeepCollectionEquality() - .equals(other.impliedProperties, impliedProperties) && + .equals(other._impliedProperties, _impliedProperties) && (identical(other.isDefault, isDefault) || other.isDefault == isDefault) && (identical(other.isFallback, isFallback) || @@ -642,14 +617,14 @@ class _$_ConstructorDetails extends _ConstructorDetails { (identical(other.escapedName, escapedName) || other.escapedName == escapedName) && const DeepCollectionEquality() - .equals(other.withDecorators, withDecorators) && + .equals(other._withDecorators, _withDecorators) && const DeepCollectionEquality() - .equals(other.implementsDecorators, implementsDecorators) && + .equals(other._implementsDecorators, _implementsDecorators) && const DeepCollectionEquality() - .equals(other.decorators, decorators) && + .equals(other._decorators, _decorators) && const DeepCollectionEquality() - .equals(other.cloneableProperties, cloneableProperties) && - const DeepCollectionEquality().equals(other.asserts, asserts)); + .equals(other._cloneableProperties, _cloneableProperties) && + const DeepCollectionEquality().equals(other._asserts, _asserts)); } @override @@ -660,42 +635,44 @@ class _$_ConstructorDetails extends _ConstructorDetails { isConst, redirectedName, parameters, - const DeepCollectionEquality().hash(impliedProperties), + const DeepCollectionEquality().hash(_impliedProperties), isDefault, isFallback, hasJsonSerializable, fullName, escapedName, - const DeepCollectionEquality().hash(withDecorators), - const DeepCollectionEquality().hash(implementsDecorators), - const DeepCollectionEquality().hash(decorators), - const DeepCollectionEquality().hash(cloneableProperties), - const DeepCollectionEquality().hash(asserts)); + const DeepCollectionEquality().hash(_withDecorators), + const DeepCollectionEquality().hash(_implementsDecorators), + const DeepCollectionEquality().hash(_decorators), + const DeepCollectionEquality().hash(_cloneableProperties), + const DeepCollectionEquality().hash(_asserts)); @JsonKey(ignore: true) @override - _$ConstructorDetailsCopyWith<_ConstructorDetails> get copyWith => - __$ConstructorDetailsCopyWithImpl<_ConstructorDetails>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_ConstructorDetailsCopyWith<_$_ConstructorDetails> get copyWith => + __$$_ConstructorDetailsCopyWithImpl<_$_ConstructorDetails>( + this, _$identity); } abstract class _ConstructorDetails extends ConstructorDetails { factory _ConstructorDetails( - {required String name, - required String unionValue, - required bool isConst, - required String redirectedName, - required ParametersTemplate parameters, - required List impliedProperties, - required bool isDefault, - required bool isFallback, - required bool hasJsonSerializable, - required String fullName, - required String escapedName, - required List withDecorators, - required List implementsDecorators, - required List decorators, - required List cloneableProperties, - required List asserts}) = _$_ConstructorDetails; + {required final String name, + required final String unionValue, + required final bool isConst, + required final String redirectedName, + required final ParametersTemplate parameters, + required final List impliedProperties, + required final bool isDefault, + required final bool isFallback, + required final bool hasJsonSerializable, + required final String fullName, + required final String escapedName, + required final List withDecorators, + required final List implementsDecorators, + required final List decorators, + required final List cloneableProperties, + required final List asserts}) = _$_ConstructorDetails; _ConstructorDetails._() : super._(); @override @@ -727,32 +704,15 @@ abstract class _ConstructorDetails extends ConstructorDetails { @override List get decorators; @override - List get cloneableProperties; + List get cloneableProperties; @override List get asserts; @override @JsonKey(ignore: true) - _$ConstructorDetailsCopyWith<_ConstructorDetails> get copyWith => + _$$_ConstructorDetailsCopyWith<_$_ConstructorDetails> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$MapConfigTearOff { - const _$MapConfigTearOff(); - - _MapConfig call( - {required bool map, required bool mapOrNull, required bool maybeMap}) { - return _MapConfig( - map: map, - mapOrNull: mapOrNull, - maybeMap: maybeMap, - ); - } -} - -/// @nodoc -const $MapConfig = _$MapConfigTearOff(); - /// @nodoc mixin _$MapConfig { bool get map => throw _privateConstructorUsedError; @@ -767,75 +727,80 @@ mixin _$MapConfig { /// @nodoc abstract class $MapConfigCopyWith<$Res> { factory $MapConfigCopyWith(MapConfig value, $Res Function(MapConfig) then) = - _$MapConfigCopyWithImpl<$Res>; + _$MapConfigCopyWithImpl<$Res, MapConfig>; + @useResult $Res call({bool map, bool mapOrNull, bool maybeMap}); } /// @nodoc -class _$MapConfigCopyWithImpl<$Res> implements $MapConfigCopyWith<$Res> { +class _$MapConfigCopyWithImpl<$Res, $Val extends MapConfig> + implements $MapConfigCopyWith<$Res> { _$MapConfigCopyWithImpl(this._value, this._then); - final MapConfig _value; // ignore: unused_field - final $Res Function(MapConfig) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? map = freezed, - Object? mapOrNull = freezed, - Object? maybeMap = freezed, + Object? map = null, + Object? mapOrNull = null, + Object? maybeMap = null, }) { return _then(_value.copyWith( - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as bool, - mapOrNull: mapOrNull == freezed + mapOrNull: null == mapOrNull ? _value.mapOrNull : mapOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeMap: maybeMap == freezed + maybeMap: null == maybeMap ? _value.maybeMap : maybeMap // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$MapConfigCopyWith<$Res> implements $MapConfigCopyWith<$Res> { - factory _$MapConfigCopyWith( - _MapConfig value, $Res Function(_MapConfig) then) = - __$MapConfigCopyWithImpl<$Res>; +abstract class _$$_MapConfigCopyWith<$Res> implements $MapConfigCopyWith<$Res> { + factory _$$_MapConfigCopyWith( + _$_MapConfig value, $Res Function(_$_MapConfig) then) = + __$$_MapConfigCopyWithImpl<$Res>; @override + @useResult $Res call({bool map, bool mapOrNull, bool maybeMap}); } /// @nodoc -class __$MapConfigCopyWithImpl<$Res> extends _$MapConfigCopyWithImpl<$Res> - implements _$MapConfigCopyWith<$Res> { - __$MapConfigCopyWithImpl(_MapConfig _value, $Res Function(_MapConfig) _then) - : super(_value, (v) => _then(v as _MapConfig)); - - @override - _MapConfig get _value => super._value as _MapConfig; +class __$$_MapConfigCopyWithImpl<$Res> + extends _$MapConfigCopyWithImpl<$Res, _$_MapConfig> + implements _$$_MapConfigCopyWith<$Res> { + __$$_MapConfigCopyWithImpl( + _$_MapConfig _value, $Res Function(_$_MapConfig) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? map = freezed, - Object? mapOrNull = freezed, - Object? maybeMap = freezed, + Object? map = null, + Object? mapOrNull = null, + Object? maybeMap = null, }) { - return _then(_MapConfig( - map: map == freezed + return _then(_$_MapConfig( + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as bool, - mapOrNull: mapOrNull == freezed + mapOrNull: null == mapOrNull ? _value.mapOrNull : mapOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeMap: maybeMap == freezed + maybeMap: null == maybeMap ? _value.maybeMap : maybeMap // ignore: cast_nullable_to_non_nullable as bool, @@ -865,7 +830,7 @@ class _$_MapConfig implements _MapConfig { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _MapConfig && + other is _$_MapConfig && (identical(other.map, map) || other.map == map) && (identical(other.mapOrNull, mapOrNull) || other.mapOrNull == mapOrNull) && @@ -878,15 +843,16 @@ class _$_MapConfig implements _MapConfig { @JsonKey(ignore: true) @override - _$MapConfigCopyWith<_MapConfig> get copyWith => - __$MapConfigCopyWithImpl<_MapConfig>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_MapConfigCopyWith<_$_MapConfig> get copyWith => + __$$_MapConfigCopyWithImpl<_$_MapConfig>(this, _$identity); } abstract class _MapConfig implements MapConfig { factory _MapConfig( - {required bool map, - required bool mapOrNull, - required bool maybeMap}) = _$_MapConfig; + {required final bool map, + required final bool mapOrNull, + required final bool maybeMap}) = _$_MapConfig; @override bool get map; @@ -896,27 +862,10 @@ abstract class _MapConfig implements MapConfig { bool get maybeMap; @override @JsonKey(ignore: true) - _$MapConfigCopyWith<_MapConfig> get copyWith => + _$$_MapConfigCopyWith<_$_MapConfig> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$WhenConfigTearOff { - const _$WhenConfigTearOff(); - - _WhenConfig call( - {required bool when, required bool whenOrNull, required bool maybeWhen}) { - return _WhenConfig( - when: when, - whenOrNull: whenOrNull, - maybeWhen: maybeWhen, - ); - } -} - -/// @nodoc -const $WhenConfig = _$WhenConfigTearOff(); - /// @nodoc mixin _$WhenConfig { bool get when => throw _privateConstructorUsedError; @@ -932,76 +881,81 @@ mixin _$WhenConfig { abstract class $WhenConfigCopyWith<$Res> { factory $WhenConfigCopyWith( WhenConfig value, $Res Function(WhenConfig) then) = - _$WhenConfigCopyWithImpl<$Res>; + _$WhenConfigCopyWithImpl<$Res, WhenConfig>; + @useResult $Res call({bool when, bool whenOrNull, bool maybeWhen}); } /// @nodoc -class _$WhenConfigCopyWithImpl<$Res> implements $WhenConfigCopyWith<$Res> { +class _$WhenConfigCopyWithImpl<$Res, $Val extends WhenConfig> + implements $WhenConfigCopyWith<$Res> { _$WhenConfigCopyWithImpl(this._value, this._then); - final WhenConfig _value; // ignore: unused_field - final $Res Function(WhenConfig) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? when = freezed, - Object? whenOrNull = freezed, - Object? maybeWhen = freezed, + Object? when = null, + Object? whenOrNull = null, + Object? maybeWhen = null, }) { return _then(_value.copyWith( - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as bool, - whenOrNull: whenOrNull == freezed + whenOrNull: null == whenOrNull ? _value.whenOrNull : whenOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeWhen: maybeWhen == freezed + maybeWhen: null == maybeWhen ? _value.maybeWhen : maybeWhen // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$WhenConfigCopyWith<$Res> implements $WhenConfigCopyWith<$Res> { - factory _$WhenConfigCopyWith( - _WhenConfig value, $Res Function(_WhenConfig) then) = - __$WhenConfigCopyWithImpl<$Res>; +abstract class _$$_WhenConfigCopyWith<$Res> + implements $WhenConfigCopyWith<$Res> { + factory _$$_WhenConfigCopyWith( + _$_WhenConfig value, $Res Function(_$_WhenConfig) then) = + __$$_WhenConfigCopyWithImpl<$Res>; @override + @useResult $Res call({bool when, bool whenOrNull, bool maybeWhen}); } /// @nodoc -class __$WhenConfigCopyWithImpl<$Res> extends _$WhenConfigCopyWithImpl<$Res> - implements _$WhenConfigCopyWith<$Res> { - __$WhenConfigCopyWithImpl( - _WhenConfig _value, $Res Function(_WhenConfig) _then) - : super(_value, (v) => _then(v as _WhenConfig)); - - @override - _WhenConfig get _value => super._value as _WhenConfig; +class __$$_WhenConfigCopyWithImpl<$Res> + extends _$WhenConfigCopyWithImpl<$Res, _$_WhenConfig> + implements _$$_WhenConfigCopyWith<$Res> { + __$$_WhenConfigCopyWithImpl( + _$_WhenConfig _value, $Res Function(_$_WhenConfig) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? when = freezed, - Object? whenOrNull = freezed, - Object? maybeWhen = freezed, + Object? when = null, + Object? whenOrNull = null, + Object? maybeWhen = null, }) { - return _then(_WhenConfig( - when: when == freezed + return _then(_$_WhenConfig( + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as bool, - whenOrNull: whenOrNull == freezed + whenOrNull: null == whenOrNull ? _value.whenOrNull : whenOrNull // ignore: cast_nullable_to_non_nullable as bool, - maybeWhen: maybeWhen == freezed + maybeWhen: null == maybeWhen ? _value.maybeWhen : maybeWhen // ignore: cast_nullable_to_non_nullable as bool, @@ -1031,7 +985,7 @@ class _$_WhenConfig implements _WhenConfig { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _WhenConfig && + other is _$_WhenConfig && (identical(other.when, when) || other.when == when) && (identical(other.whenOrNull, whenOrNull) || other.whenOrNull == whenOrNull) && @@ -1044,15 +998,16 @@ class _$_WhenConfig implements _WhenConfig { @JsonKey(ignore: true) @override - _$WhenConfigCopyWith<_WhenConfig> get copyWith => - __$WhenConfigCopyWithImpl<_WhenConfig>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_WhenConfigCopyWith<_$_WhenConfig> get copyWith => + __$$_WhenConfigCopyWithImpl<_$_WhenConfig>(this, _$identity); } abstract class _WhenConfig implements WhenConfig { factory _WhenConfig( - {required bool when, - required bool whenOrNull, - required bool maybeWhen}) = _$_WhenConfig; + {required final bool when, + required final bool whenOrNull, + required final bool maybeWhen}) = _$_WhenConfig; @override bool get when; @@ -1062,55 +1017,10 @@ abstract class _WhenConfig implements WhenConfig { bool get maybeWhen; @override @JsonKey(ignore: true) - _$WhenConfigCopyWith<_WhenConfig> get copyWith => + _$$_WhenConfigCopyWith<_$_WhenConfig> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$DataTearOff { - const _$DataTearOff(); - - _Data call( - {required String name, - required String unionKey, - required bool generateCopyWith, - required bool generateEqual, - required bool generateToString, - required MapConfig map, - required WhenConfig when, - required bool generateFromJson, - required bool generateToJson, - required bool makeCollectionsImmutable, - required List concretePropertiesName, - required List constructors, - required GenericsDefinitionTemplate genericsDefinitionTemplate, - required GenericsParameterTemplate genericsParameterTemplate, - required bool shouldUseExtends, - required bool genericArgumentFactories}) { - return _Data( - name: name, - unionKey: unionKey, - generateCopyWith: generateCopyWith, - generateEqual: generateEqual, - generateToString: generateToString, - map: map, - when: when, - generateFromJson: generateFromJson, - generateToJson: generateToJson, - makeCollectionsImmutable: makeCollectionsImmutable, - concretePropertiesName: concretePropertiesName, - constructors: constructors, - genericsDefinitionTemplate: genericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate, - shouldUseExtends: shouldUseExtends, - genericArgumentFactories: genericArgumentFactories, - ); - } -} - -/// @nodoc -const $Data = _$DataTearOff(); - /// @nodoc mixin _$Data { String get name => throw _privateConstructorUsedError; @@ -1140,7 +1050,8 @@ mixin _$Data { /// @nodoc abstract class $DataCopyWith<$Res> { factory $DataCopyWith(Data value, $Res Function(Data) then) = - _$DataCopyWithImpl<$Res>; + _$DataCopyWithImpl<$Res, Data>; + @useResult $Res call( {String name, String unionKey, @@ -1164,120 +1075,126 @@ abstract class $DataCopyWith<$Res> { } /// @nodoc -class _$DataCopyWithImpl<$Res> implements $DataCopyWith<$Res> { +class _$DataCopyWithImpl<$Res, $Val extends Data> + implements $DataCopyWith<$Res> { _$DataCopyWithImpl(this._value, this._then); - final Data _value; // ignore: unused_field - final $Res Function(Data) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionKey = freezed, - Object? generateCopyWith = freezed, - Object? generateEqual = freezed, - Object? generateToString = freezed, - Object? map = freezed, - Object? when = freezed, - Object? generateFromJson = freezed, - Object? generateToJson = freezed, - Object? makeCollectionsImmutable = freezed, - Object? concretePropertiesName = freezed, - Object? constructors = freezed, - Object? genericsDefinitionTemplate = freezed, - Object? genericsParameterTemplate = freezed, - Object? shouldUseExtends = freezed, - Object? genericArgumentFactories = freezed, + Object? name = null, + Object? unionKey = null, + Object? generateCopyWith = null, + Object? generateEqual = null, + Object? generateToString = null, + Object? map = null, + Object? when = null, + Object? generateFromJson = null, + Object? generateToJson = null, + Object? makeCollectionsImmutable = null, + Object? concretePropertiesName = null, + Object? constructors = null, + Object? genericsDefinitionTemplate = null, + Object? genericsParameterTemplate = null, + Object? shouldUseExtends = null, + Object? genericArgumentFactories = null, }) { return _then(_value.copyWith( - name: name == freezed + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionKey: unionKey == freezed + unionKey: null == unionKey ? _value.unionKey : unionKey // ignore: cast_nullable_to_non_nullable as String, - generateCopyWith: generateCopyWith == freezed + generateCopyWith: null == generateCopyWith ? _value.generateCopyWith : generateCopyWith // ignore: cast_nullable_to_non_nullable as bool, - generateEqual: generateEqual == freezed + generateEqual: null == generateEqual ? _value.generateEqual : generateEqual // ignore: cast_nullable_to_non_nullable as bool, - generateToString: generateToString == freezed + generateToString: null == generateToString ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as MapConfig, - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as WhenConfig, - generateFromJson: generateFromJson == freezed + generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable as bool, - generateToJson: generateToJson == freezed + generateToJson: null == generateToJson ? _value.generateToJson : generateToJson // ignore: cast_nullable_to_non_nullable as bool, - makeCollectionsImmutable: makeCollectionsImmutable == freezed + makeCollectionsImmutable: null == makeCollectionsImmutable ? _value.makeCollectionsImmutable : makeCollectionsImmutable // ignore: cast_nullable_to_non_nullable as bool, - concretePropertiesName: concretePropertiesName == freezed + concretePropertiesName: null == concretePropertiesName ? _value.concretePropertiesName : concretePropertiesName // ignore: cast_nullable_to_non_nullable as List, - constructors: constructors == freezed + constructors: null == constructors ? _value.constructors : constructors // ignore: cast_nullable_to_non_nullable as List, - genericsDefinitionTemplate: genericsDefinitionTemplate == freezed + genericsDefinitionTemplate: null == genericsDefinitionTemplate ? _value.genericsDefinitionTemplate : genericsDefinitionTemplate // ignore: cast_nullable_to_non_nullable as GenericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate == freezed + genericsParameterTemplate: null == genericsParameterTemplate ? _value.genericsParameterTemplate : genericsParameterTemplate // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - shouldUseExtends: shouldUseExtends == freezed + shouldUseExtends: null == shouldUseExtends ? _value.shouldUseExtends : shouldUseExtends // ignore: cast_nullable_to_non_nullable as bool, - genericArgumentFactories: genericArgumentFactories == freezed + genericArgumentFactories: null == genericArgumentFactories ? _value.genericArgumentFactories : genericArgumentFactories // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } @override + @pragma('vm:prefer-inline') $MapConfigCopyWith<$Res> get map { return $MapConfigCopyWith<$Res>(_value.map, (value) { - return _then(_value.copyWith(map: value)); + return _then(_value.copyWith(map: value) as $Val); }); } @override + @pragma('vm:prefer-inline') $WhenConfigCopyWith<$Res> get when { return $WhenConfigCopyWith<$Res>(_value.when, (value) { - return _then(_value.copyWith(when: value)); + return _then(_value.copyWith(when: value) as $Val); }); } } /// @nodoc -abstract class _$DataCopyWith<$Res> implements $DataCopyWith<$Res> { - factory _$DataCopyWith(_Data value, $Res Function(_Data) then) = - __$DataCopyWithImpl<$Res>; +abstract class _$$_DataCopyWith<$Res> implements $DataCopyWith<$Res> { + factory _$$_DataCopyWith(_$_Data value, $Res Function(_$_Data) then) = + __$$_DataCopyWithImpl<$Res>; @override + @useResult $Res call( {String name, String unionKey, @@ -1303,95 +1220,93 @@ abstract class _$DataCopyWith<$Res> implements $DataCopyWith<$Res> { } /// @nodoc -class __$DataCopyWithImpl<$Res> extends _$DataCopyWithImpl<$Res> - implements _$DataCopyWith<$Res> { - __$DataCopyWithImpl(_Data _value, $Res Function(_Data) _then) - : super(_value, (v) => _then(v as _Data)); - - @override - _Data get _value => super._value as _Data; +class __$$_DataCopyWithImpl<$Res> extends _$DataCopyWithImpl<$Res, _$_Data> + implements _$$_DataCopyWith<$Res> { + __$$_DataCopyWithImpl(_$_Data _value, $Res Function(_$_Data) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? name = freezed, - Object? unionKey = freezed, - Object? generateCopyWith = freezed, - Object? generateEqual = freezed, - Object? generateToString = freezed, - Object? map = freezed, - Object? when = freezed, - Object? generateFromJson = freezed, - Object? generateToJson = freezed, - Object? makeCollectionsImmutable = freezed, - Object? concretePropertiesName = freezed, - Object? constructors = freezed, - Object? genericsDefinitionTemplate = freezed, - Object? genericsParameterTemplate = freezed, - Object? shouldUseExtends = freezed, - Object? genericArgumentFactories = freezed, + Object? name = null, + Object? unionKey = null, + Object? generateCopyWith = null, + Object? generateEqual = null, + Object? generateToString = null, + Object? map = null, + Object? when = null, + Object? generateFromJson = null, + Object? generateToJson = null, + Object? makeCollectionsImmutable = null, + Object? concretePropertiesName = null, + Object? constructors = null, + Object? genericsDefinitionTemplate = null, + Object? genericsParameterTemplate = null, + Object? shouldUseExtends = null, + Object? genericArgumentFactories = null, }) { - return _then(_Data( - name: name == freezed + return _then(_$_Data( + name: null == name ? _value.name : name // ignore: cast_nullable_to_non_nullable as String, - unionKey: unionKey == freezed + unionKey: null == unionKey ? _value.unionKey : unionKey // ignore: cast_nullable_to_non_nullable as String, - generateCopyWith: generateCopyWith == freezed + generateCopyWith: null == generateCopyWith ? _value.generateCopyWith : generateCopyWith // ignore: cast_nullable_to_non_nullable as bool, - generateEqual: generateEqual == freezed + generateEqual: null == generateEqual ? _value.generateEqual : generateEqual // ignore: cast_nullable_to_non_nullable as bool, - generateToString: generateToString == freezed + generateToString: null == generateToString ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: map == freezed + map: null == map ? _value.map : map // ignore: cast_nullable_to_non_nullable as MapConfig, - when: when == freezed + when: null == when ? _value.when : when // ignore: cast_nullable_to_non_nullable as WhenConfig, - generateFromJson: generateFromJson == freezed + generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable as bool, - generateToJson: generateToJson == freezed + generateToJson: null == generateToJson ? _value.generateToJson : generateToJson // ignore: cast_nullable_to_non_nullable as bool, - makeCollectionsImmutable: makeCollectionsImmutable == freezed + makeCollectionsImmutable: null == makeCollectionsImmutable ? _value.makeCollectionsImmutable : makeCollectionsImmutable // ignore: cast_nullable_to_non_nullable as bool, - concretePropertiesName: concretePropertiesName == freezed - ? _value.concretePropertiesName + concretePropertiesName: null == concretePropertiesName + ? _value._concretePropertiesName : concretePropertiesName // ignore: cast_nullable_to_non_nullable as List, - constructors: constructors == freezed - ? _value.constructors + constructors: null == constructors + ? _value._constructors : constructors // ignore: cast_nullable_to_non_nullable as List, - genericsDefinitionTemplate: genericsDefinitionTemplate == freezed + genericsDefinitionTemplate: null == genericsDefinitionTemplate ? _value.genericsDefinitionTemplate : genericsDefinitionTemplate // ignore: cast_nullable_to_non_nullable as GenericsDefinitionTemplate, - genericsParameterTemplate: genericsParameterTemplate == freezed + genericsParameterTemplate: null == genericsParameterTemplate ? _value.genericsParameterTemplate : genericsParameterTemplate // ignore: cast_nullable_to_non_nullable as GenericsParameterTemplate, - shouldUseExtends: shouldUseExtends == freezed + shouldUseExtends: null == shouldUseExtends ? _value.shouldUseExtends : shouldUseExtends // ignore: cast_nullable_to_non_nullable as bool, - genericArgumentFactories: genericArgumentFactories == freezed + genericArgumentFactories: null == genericArgumentFactories ? _value.genericArgumentFactories : genericArgumentFactories // ignore: cast_nullable_to_non_nullable as bool, @@ -1413,13 +1328,15 @@ class _$_Data implements _Data { required this.generateFromJson, required this.generateToJson, required this.makeCollectionsImmutable, - required this.concretePropertiesName, - required this.constructors, + required final List concretePropertiesName, + required final List constructors, required this.genericsDefinitionTemplate, required this.genericsParameterTemplate, required this.shouldUseExtends, required this.genericArgumentFactories}) - : assert(constructors.isNotEmpty); + : assert(constructors.isNotEmpty), + _concretePropertiesName = concretePropertiesName, + _constructors = constructors; @override final String name; @@ -1441,10 +1358,20 @@ class _$_Data implements _Data { final bool generateToJson; @override final bool makeCollectionsImmutable; + final List _concretePropertiesName; @override - final List concretePropertiesName; + List get concretePropertiesName { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_concretePropertiesName); + } + + final List _constructors; @override - final List constructors; + List get constructors { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_constructors); + } + @override final GenericsDefinitionTemplate genericsDefinitionTemplate; @override @@ -1463,7 +1390,7 @@ class _$_Data implements _Data { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Data && + other is _$_Data && (identical(other.name, name) || other.name == name) && (identical(other.unionKey, unionKey) || other.unionKey == unionKey) && @@ -1482,10 +1409,10 @@ class _$_Data implements _Data { (identical( other.makeCollectionsImmutable, makeCollectionsImmutable) || other.makeCollectionsImmutable == makeCollectionsImmutable) && + const DeepCollectionEquality().equals( + other._concretePropertiesName, _concretePropertiesName) && const DeepCollectionEquality() - .equals(other.concretePropertiesName, concretePropertiesName) && - const DeepCollectionEquality() - .equals(other.constructors, constructors) && + .equals(other._constructors, _constructors) && (identical(other.genericsDefinitionTemplate, genericsDefinitionTemplate) || other.genericsDefinitionTemplate == @@ -1513,8 +1440,8 @@ class _$_Data implements _Data { generateFromJson, generateToJson, makeCollectionsImmutable, - const DeepCollectionEquality().hash(concretePropertiesName), - const DeepCollectionEquality().hash(constructors), + const DeepCollectionEquality().hash(_concretePropertiesName), + const DeepCollectionEquality().hash(_constructors), genericsDefinitionTemplate, genericsParameterTemplate, shouldUseExtends, @@ -1522,28 +1449,29 @@ class _$_Data implements _Data { @JsonKey(ignore: true) @override - _$DataCopyWith<_Data> get copyWith => - __$DataCopyWithImpl<_Data>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_DataCopyWith<_$_Data> get copyWith => + __$$_DataCopyWithImpl<_$_Data>(this, _$identity); } abstract class _Data implements Data { factory _Data( - {required String name, - required String unionKey, - required bool generateCopyWith, - required bool generateEqual, - required bool generateToString, - required MapConfig map, - required WhenConfig when, - required bool generateFromJson, - required bool generateToJson, - required bool makeCollectionsImmutable, - required List concretePropertiesName, - required List constructors, - required GenericsDefinitionTemplate genericsDefinitionTemplate, - required GenericsParameterTemplate genericsParameterTemplate, - required bool shouldUseExtends, - required bool genericArgumentFactories}) = _$_Data; + {required final String name, + required final String unionKey, + required final bool generateCopyWith, + required final bool generateEqual, + required final bool generateToString, + required final MapConfig map, + required final WhenConfig when, + required final bool generateFromJson, + required final bool generateToJson, + required final bool makeCollectionsImmutable, + required final List concretePropertiesName, + required final List constructors, + required final GenericsDefinitionTemplate genericsDefinitionTemplate, + required final GenericsParameterTemplate genericsParameterTemplate, + required final bool shouldUseExtends, + required final bool genericArgumentFactories}) = _$_Data; @override String get name; @@ -1579,24 +1507,9 @@ abstract class _Data implements Data { bool get genericArgumentFactories; @override @JsonKey(ignore: true) - _$DataCopyWith<_Data> get copyWith => throw _privateConstructorUsedError; + _$$_DataCopyWith<_$_Data> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$GlobalDataTearOff { - const _$GlobalDataTearOff(); - - _GlobalData call({required bool hasJson, required bool hasDiagnostics}) { - return _GlobalData( - hasJson: hasJson, - hasDiagnostics: hasDiagnostics, - ); - } -} - -/// @nodoc -const $GlobalData = _$GlobalDataTearOff(); - /// @nodoc mixin _$GlobalData { bool get hasJson => throw _privateConstructorUsedError; @@ -1611,66 +1524,71 @@ mixin _$GlobalData { abstract class $GlobalDataCopyWith<$Res> { factory $GlobalDataCopyWith( GlobalData value, $Res Function(GlobalData) then) = - _$GlobalDataCopyWithImpl<$Res>; + _$GlobalDataCopyWithImpl<$Res, GlobalData>; + @useResult $Res call({bool hasJson, bool hasDiagnostics}); } /// @nodoc -class _$GlobalDataCopyWithImpl<$Res> implements $GlobalDataCopyWith<$Res> { +class _$GlobalDataCopyWithImpl<$Res, $Val extends GlobalData> + implements $GlobalDataCopyWith<$Res> { _$GlobalDataCopyWithImpl(this._value, this._then); - final GlobalData _value; // ignore: unused_field - final $Res Function(GlobalData) _then; + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + @pragma('vm:prefer-inline') @override $Res call({ - Object? hasJson = freezed, - Object? hasDiagnostics = freezed, + Object? hasJson = null, + Object? hasDiagnostics = null, }) { return _then(_value.copyWith( - hasJson: hasJson == freezed + hasJson: null == hasJson ? _value.hasJson : hasJson // ignore: cast_nullable_to_non_nullable as bool, - hasDiagnostics: hasDiagnostics == freezed + hasDiagnostics: null == hasDiagnostics ? _value.hasDiagnostics : hasDiagnostics // ignore: cast_nullable_to_non_nullable as bool, - )); + ) as $Val); } } /// @nodoc -abstract class _$GlobalDataCopyWith<$Res> implements $GlobalDataCopyWith<$Res> { - factory _$GlobalDataCopyWith( - _GlobalData value, $Res Function(_GlobalData) then) = - __$GlobalDataCopyWithImpl<$Res>; +abstract class _$$_GlobalDataCopyWith<$Res> + implements $GlobalDataCopyWith<$Res> { + factory _$$_GlobalDataCopyWith( + _$_GlobalData value, $Res Function(_$_GlobalData) then) = + __$$_GlobalDataCopyWithImpl<$Res>; @override + @useResult $Res call({bool hasJson, bool hasDiagnostics}); } /// @nodoc -class __$GlobalDataCopyWithImpl<$Res> extends _$GlobalDataCopyWithImpl<$Res> - implements _$GlobalDataCopyWith<$Res> { - __$GlobalDataCopyWithImpl( - _GlobalData _value, $Res Function(_GlobalData) _then) - : super(_value, (v) => _then(v as _GlobalData)); - - @override - _GlobalData get _value => super._value as _GlobalData; +class __$$_GlobalDataCopyWithImpl<$Res> + extends _$GlobalDataCopyWithImpl<$Res, _$_GlobalData> + implements _$$_GlobalDataCopyWith<$Res> { + __$$_GlobalDataCopyWithImpl( + _$_GlobalData _value, $Res Function(_$_GlobalData) _then) + : super(_value, _then); + @pragma('vm:prefer-inline') @override $Res call({ - Object? hasJson = freezed, - Object? hasDiagnostics = freezed, + Object? hasJson = null, + Object? hasDiagnostics = null, }) { - return _then(_GlobalData( - hasJson: hasJson == freezed + return _then(_$_GlobalData( + hasJson: null == hasJson ? _value.hasJson : hasJson // ignore: cast_nullable_to_non_nullable as bool, - hasDiagnostics: hasDiagnostics == freezed + hasDiagnostics: null == hasDiagnostics ? _value.hasDiagnostics : hasDiagnostics // ignore: cast_nullable_to_non_nullable as bool, @@ -1697,7 +1615,7 @@ class _$_GlobalData implements _GlobalData { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _GlobalData && + other is _$_GlobalData && (identical(other.hasJson, hasJson) || other.hasJson == hasJson) && (identical(other.hasDiagnostics, hasDiagnostics) || other.hasDiagnostics == hasDiagnostics)); @@ -1708,13 +1626,15 @@ class _$_GlobalData implements _GlobalData { @JsonKey(ignore: true) @override - _$GlobalDataCopyWith<_GlobalData> get copyWith => - __$GlobalDataCopyWithImpl<_GlobalData>(this, _$identity); + @pragma('vm:prefer-inline') + _$$_GlobalDataCopyWith<_$_GlobalData> get copyWith => + __$$_GlobalDataCopyWithImpl<_$_GlobalData>(this, _$identity); } abstract class _GlobalData implements GlobalData { - factory _GlobalData({required bool hasJson, required bool hasDiagnostics}) = - _$_GlobalData; + factory _GlobalData( + {required final bool hasJson, + required final bool hasDiagnostics}) = _$_GlobalData; @override bool get hasJson; @@ -1722,6 +1642,6 @@ abstract class _GlobalData implements GlobalData { bool get hasDiagnostics; @override @JsonKey(ignore: true) - _$GlobalDataCopyWith<_GlobalData> get copyWith => + _$$_GlobalDataCopyWith<_$_GlobalData> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 9e9b6234..8fe3db33 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -41,7 +41,7 @@ ${copyWith?.abstractCopyWithGetter ?? ''} ${copyWith?.commonInterface ?? ''} -${copyWith?.commonContreteImpl ?? ''} +${copyWith?.commonConcreteImpl ?? ''} '''; } diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index 9809010c..655d730d 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -8,8 +8,9 @@ class CopyWith { required this.clonedClassName, required this.genericsDefinition, required this.genericsParameter, - required this.allProperties, required this.cloneableProperties, + required this.readableProperties, + required this.deepCloneableProperties, required this.data, this.parent, }); @@ -24,8 +25,9 @@ class CopyWith { final String clonedClassName; final GenericsDefinitionTemplate genericsDefinition; final GenericsParameterTemplate genericsParameter; - final List allProperties; - final List cloneableProperties; + final List cloneableProperties; + final List readableProperties; + final List deepCloneableProperties; final CopyWith? parent; final Data data; @@ -33,10 +35,11 @@ class CopyWith { /// if the raw collection can be accessed instead. bool get canAccessRawCollection => parent != null; - String get interface => _interface(appendGenericToFactory: false); - String get commonInterface => _interface(appendGenericToFactory: true); + String get interface => _deepCopyInterface(appendGenericToFactory: false); + String get commonInterface => + _deepCopyInterface(appendGenericToFactory: true); - String _interface({required bool appendGenericToFactory}) { + String _deepCopyInterface({required bool appendGenericToFactory}) { var implements = _hasSuperClass ? 'implements ${parent!._abstractClassName}${genericsParameter.append('\$Res')}' : ''; @@ -54,23 +57,40 @@ ${_abstractDeepCopyMethods().join()} }'''; } - bool get _hasSuperClass { - return parent != null && parent!.allProperties.isNotEmpty; + String get abstractCopyWithGetter { + if (cloneableProperties.isEmpty) return ''; + + return _maybeOverride( + ''' +@JsonKey(ignore: true) +$_abstractClassName${genericsParameter.append('$clonedClassName$genericsParameter')} get copyWith => throw $privConstUsedErrorVarName; +''', + ); } - String get commonContreteImpl { + String get concreteCopyWithGetter { + if (cloneableProperties.isEmpty) return ''; + return ''' +@JsonKey(ignore: true) +@override +@pragma('vm:prefer-inline') +$_abstractClassName${genericsParameter.append('$clonedClassName$genericsParameter')} get copyWith => $_implClassName${genericsParameter.append('$clonedClassName$genericsParameter')}(this, _\$identity); +'''; + } + + String get commonConcreteImpl { var copyWith = ''; - if (allProperties.isNotEmpty) { + if (cloneableProperties.isNotEmpty) { final prototype = _concreteCopyWithPrototype( - properties: allProperties, + properties: cloneableProperties, methodName: 'call', ); final body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: allProperties.map((e) { + namedParameters: cloneableProperties.map((e) { return Parameter( decorators: e.decorators, name: e.name, @@ -114,38 +134,67 @@ ${_deepCopyMethods(isConcrete: false).join()} '''; } + /// The implementation of the callable class that contains both the copyWith + /// and the cloneable properties. + String concreteImpl(ParametersTemplate parametersTemplate) { + return ''' +/// @nodoc +class $_implClassName${genericsDefinition.append('\$Res')} extends ${parent!._implClassName}${genericsParameter.append('\$Res').append('$clonedClassName$genericsParameter')} implements $_abstractClassName${genericsParameter.append('\$Res')} { + $_implClassName($clonedClassName$genericsParameter _value, \$Res Function($clonedClassName$genericsParameter) _then) + : super(_value, _then); + + +${_copyWithMethod(parametersTemplate)} + +${_deepCopyMethods(isConcrete: true).join()} +}'''; + } + + bool get _hasSuperClass { + return parent != null && parent!.cloneableProperties.isNotEmpty; + } + Iterable _abstractDeepCopyMethods() sync* { - for (final cloneableProperty in cloneableProperties) { + for (final deepCloneableProperty in deepCloneableProperties) { var leading = ''; if (_hasSuperClass && - parent!.cloneableProperties - .any((c) => c.name == cloneableProperty.name)) { + parent!.deepCloneableProperties + .any((c) => c.name == deepCloneableProperty.name)) { leading = '@override '; } - final nullabilitySuffix = cloneableProperty.nullable ? '?' : ''; + final nullabilitySuffix = deepCloneableProperty.nullable ? '?' : ''; - yield '$leading${_clonerInterfaceFor(cloneableProperty)}$nullabilitySuffix get ${cloneableProperty.name};'; + yield '$leading${_clonerInterfaceFor(deepCloneableProperty)}$nullabilitySuffix get ${deepCloneableProperty.name};'; } } String _copyWithPrototype(String methodName) { - if (allProperties.isEmpty) return ''; + if (cloneableProperties.isEmpty) return ''; return _copyWithProtypeFor( methodName: methodName, - properties: allProperties, + properties: cloneableProperties, ); } + String _concreteCopyWithPrototype({ + required List properties, + required String methodName, + }) { + final parameters = properties.map((p) { + return 'Object? ${p.name} = ${_defaultValue(isNullable: p.isNullable)},'; + }).join(); + + return '\$Res $methodName({$parameters})'; + } + String _copyWithProtypeFor({ required String methodName, required List properties, }) { final parameters = properties.map((p) { - final type = p.commonSubtype ?? p.type; - - return '${p.decorators.join()} covariant $type ${p.name}'; + return '${p.decorators.join()} ${p.type} ${p.name}'; }).join(','); return _maybeOverride(''' @@ -156,32 +205,11 @@ $parameters '''); } - String get abstractCopyWithGetter { - if (allProperties.isEmpty) return ''; - - return _maybeOverride( - ''' -@JsonKey(ignore: true) -$_abstractClassName${genericsParameter.append('$clonedClassName$genericsParameter')} get copyWith => throw $privConstUsedErrorVarName; -''', - ); - } - - String get concreteCopyWithGetter { - if (allProperties.isEmpty) return ''; - return ''' -@JsonKey(ignore: true) -@override -@pragma('vm:prefer-inline') -$_abstractClassName${genericsParameter.append('$clonedClassName$genericsParameter')} get copyWith => $_implClassName${genericsParameter.append('$clonedClassName$genericsParameter')}(this, _\$identity); -'''; - } - String _copyWithMethod(ParametersTemplate parametersTemplate) { - if (allProperties.isEmpty) return ''; + if (cloneableProperties.isEmpty) return ''; final prototype = _concreteCopyWithPrototype( - properties: allProperties, + properties: cloneableProperties, methodName: 'call', ); @@ -213,28 +241,45 @@ $s'''; required String returnType, String returnCast = '', }) { - String parameterToValue(Parameter p) { - var propertyName = p.name; + String thisPropertyFor({ + required Property propertyGetterForCopyWithParameter, + required Parameter to, + }) { + var propertyName = to.name; if (canAccessRawCollection && - (p.isDartList || p.isDartMap || p.isDartSet) && + (to.isDartList || to.isDartMap || to.isDartSet) && data.makeCollectionsImmutable) { propertyName = '_$propertyName'; } - var ternary = - '${_defaultValue(isNullable: p.isNullable)} == ${p.name} ? $accessor.$propertyName '; + var cast = ''; + if (propertyGetterForCopyWithParameter.type != to.type) cast = '!'; - final type = p.commonSubtype ?? p.type; - if (p.commonSubtype != null && p.type != p.commonSubtype) { - ternary += 'as $type '; - } + return '$accessor.$propertyName$cast'; + } - ternary += ': ${p.name} '; + String parameterAssignmentFor(Parameter p) { + var result = '${p.name} '; if (p.type != 'Object?' && p.type != 'Object' && p.type != null) { - ternary += _ignoreLints('as ${p.type}'); + result += _ignoreLints('as ${p.type}'); } - return '$ternary,'; + return result; + } + + String parameterToValue(Parameter p) { + final propertyGetterForCopyWithParameter = + readableProperties.firstWhere((element) => element.name == p.name); + + final condition = + '${_defaultValue(isNullable: p.isNullable)} == ${p.name}'; + + final thisProperty = thisPropertyFor( + propertyGetterForCopyWithParameter: propertyGetterForCopyWithParameter, + to: p, + ); + + return '$condition ? $thisProperty : ${parameterAssignmentFor(p)},'; } final constructorParameters = StringBuffer() @@ -257,40 +302,13 @@ $constructorParameters }'''; } - String _concreteCopyWithPrototype({ - required List properties, - required String methodName, - }) { - final parameters = properties.map((p) { - return 'Object? ${p.name} = ${_defaultValue(isNullable: p.isNullable)},'; - }).join(); - - return '\$Res $methodName({$parameters})'; - } - String get _implClassName => '_${_abstractClassName}Impl'; - /// The implementation of the callable class that contains both the copyWith - /// and the cloneable properties. - String concreteImpl(ParametersTemplate parametersTemplate) { - return ''' -/// @nodoc -class $_implClassName${genericsDefinition.append('\$Res')} extends ${parent!._implClassName}${genericsParameter.append('\$Res').append('$clonedClassName$genericsParameter')} implements $_abstractClassName${genericsParameter.append('\$Res')} { - $_implClassName($clonedClassName$genericsParameter _value, \$Res Function($clonedClassName$genericsParameter) _then) - : super(_value, _then); - - -${_copyWithMethod(parametersTemplate)} - -${_deepCopyMethods(isConcrete: true).join()} -}'''; - } - Iterable _deepCopyMethods({required bool isConcrete}) sync* { final toGenerateProperties = parent == null - ? cloneableProperties - : cloneableProperties.where((property) { - return !parent!.cloneableProperties + ? deepCloneableProperties + : deepCloneableProperties.where((property) { + return !parent!.deepCloneableProperties .any((p) => p.name == property.name); }); @@ -323,7 +341,7 @@ $returnType get ${cloneableProperty.name} { } } - String _clonerInterfaceFor(CloneableProperty cloneableProperty) { + String _clonerInterfaceFor(DeepCloneableProperty cloneableProperty) { final name = interfaceNameFrom(cloneableProperty.typeName); return '$name${cloneableProperty.genericParameters.append('\$Res')}'; } diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index e5f81406..f99d987b 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -112,10 +112,70 @@ void main() { param.copyWith( // Since not all unions have a nullable property, we cannot assign "null" // on the shared interface. - // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER + // expect-error: ARGUMENT_TYPE_NOT_ASSIGNABLE nullabilityDifference: null, // Since not all unions use the same type, we can't clone that property at all. - // expect-error: ASSIGNMENT_TO_FINAL_NO_SETTER + // expect-error: UNDEFINED_NAMED_PARAMETER + typeDifference: 42, + ); +} +'''), compiles); + }); + }); + + group('DeepCopySharedProperties', () { + test('Can clone properties with nullability difference', () { + const value = DeepCopySharedProperties( + CommonSuperSubtype0( + nullabilityDifference: 42, + typeDifference: 21, + ), + ); + + expect( + value.copyWith( + value: const CommonSuperSubtype0( + nullabilityDifference: 84, + typeDifference: 21, + ), + ), + const DeepCopySharedProperties( + CommonSuperSubtype0( + nullabilityDifference: 84, + typeDifference: 21, + ), + ), + ); + + expect( + value.copyWith.value(nullabilityDifference: 84), + const DeepCopySharedProperties( + CommonSuperSubtype0( + nullabilityDifference: 84, + typeDifference: 21, + ), + ), + ); + }); + + test('Cannot clone with type mismatch', () async { + await expectLater(library.withCode(''' +import 'integration/common_types.dart'; + +void main() { + final param = DeepCopySharedProperties( + CommonSuperSubtype( + nullabilityDifference: 42, + typeDifference: 21, + ), + ); + param.copyWith.value( + // Since not all unions have a nullable property, we cannot assign "null" + // on the shared interface. + // expect-error: ARGUMENT_TYPE_NOT_ASSIGNABLE + nullabilityDifference: null, + // Since not all unions use the same type, we can't clone that property at all. + // expect-error: UNDEFINED_NAMED_PARAMETER typeDifference: 42, ); } diff --git a/packages/freezed/test/integration/common_types.dart b/packages/freezed/test/integration/common_types.dart index e2dac320..ef0cc83d 100644 --- a/packages/freezed/test/integration/common_types.dart +++ b/packages/freezed/test/integration/common_types.dart @@ -17,16 +17,9 @@ class CommonSuperSubtype with _$CommonSuperSubtype { } @freezed -class CommonTypeNested with _$CommonTypeNested { - const factory CommonTypeNested.one({required int a}) = CommonTypeNestedOne; - const factory CommonTypeNested.two({required num a}) = CommonTypeNestedTwo; -} - -@freezed -class CommonTypeNestedContainer with _$CommonTypeNestedContainer { - const factory CommonTypeNestedContainer({ - required CommonTypeNested internal, - }) = _CommonTypeNestedContainer; +class DeepCopySharedProperties with _$DeepCopySharedProperties { + const factory DeepCopySharedProperties(CommonSuperSubtype value) = + _DeepCopySharedProperties; } @unfreezed From 2f9c52230e2132ac167186edeaba718a7814ed5d Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 30 Nov 2022 15:04:35 +0100 Subject: [PATCH 23/23] Remove dead code --- .../lib/src/templates/concrete_template.dart | 2 -- .../freezed/lib/src/templates/copy_with.dart | 4 +--- .../lib/src/templates/parameter_template.dart | 22 ------------------ .../freezed/lib/src/templates/properties.dart | 23 ++----------------- .../freezed/lib/src/templates/prototypes.dart | 4 ---- 5 files changed, 3 insertions(+), 52 deletions(-) diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index f10506e9..260be950 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -135,8 +135,6 @@ ${copyWith?.abstractCopyWithGetter ?? ''} doc: '', isPossiblyDartCollection: false, showDefaultValue: false, - commonSupertype: null, - commonSubtype: null, parameterElement: null, ); diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index 655d730d..d2211b0e 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -102,11 +102,9 @@ $_abstractClassName${genericsParameter.append('$clonedClassName$genericsParamete showDefaultValue: false, isRequired: false, defaultValueSource: '', - type: e.commonSupertype ?? e.type, + type: e.type, doc: e.doc, isPossiblyDartCollection: e.isPossiblyDartCollection, - commonSupertype: e.commonSupertype, - commonSubtype: e.commonSubtype, parameterElement: null, ); }).toList(), diff --git a/packages/freezed/lib/src/templates/parameter_template.dart b/packages/freezed/lib/src/templates/parameter_template.dart index 86f22377..18d94223 100644 --- a/packages/freezed/lib/src/templates/parameter_template.dart +++ b/packages/freezed/lib/src/templates/parameter_template.dart @@ -82,8 +82,6 @@ class ParametersTemplate { doc: await documentationOfParameter(e, buildStep), isPossiblyDartCollection: e.type.isPossiblyDartCollection, showDefaultValue: true, - commonSupertype: null, - commonSubtype: null, parameterElement: e, ); @@ -187,8 +185,6 @@ class Parameter { required this.isFinal, required this.isPossiblyDartCollection, required this.showDefaultValue, - required this.commonSupertype, - required this.commonSubtype, required this.parameterElement, }); @@ -207,8 +203,6 @@ class Parameter { showDefaultValue: p.showDefaultValue, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, - commonSubtype: p.commonSubtype, - commonSupertype: p.commonSupertype, parameterElement: p.parameterElement, ); @@ -225,8 +219,6 @@ class Parameter { final bool isPossiblyDartCollection; final bool isFinal; final String doc; - final String? commonSupertype; - final String? commonSubtype; final ParameterElement? parameterElement; Parameter copyWith({ @@ -244,8 +236,6 @@ class Parameter { bool? isDartMap, bool? isDartSet, bool? isFinal, - String? commonSupertype, - String? commonSubtype, }) => Parameter( type: type ?? this.type, @@ -262,8 +252,6 @@ class Parameter { isFinal: isFinal ?? this.isFinal, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, - commonSupertype: commonSupertype ?? this.commonSupertype, - commonSubtype: commonSubtype ?? this.commonSubtype, parameterElement: parameterElement, ); @@ -300,8 +288,6 @@ class LocalParameter extends Parameter { required List decorators, required String doc, required bool isPossiblyDartCollection, - required String? commonSupertype, - required String? commonSubtype, required ParameterElement? parameterElement, }) : super( name: name, @@ -317,8 +303,6 @@ class LocalParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, - commonSupertype: commonSupertype, - commonSubtype: commonSubtype, parameterElement: parameterElement, ); @@ -336,8 +320,6 @@ class LocalParameter extends Parameter { decorators: p.decorators, doc: p.doc, isPossiblyDartCollection: p.isPossiblyDartCollection, - commonSupertype: p.commonSupertype, - commonSubtype: p.commonSubtype, parameterElement: p.parameterElement, ); @@ -372,8 +354,6 @@ class CallbackParameter extends Parameter { required this.parameters, required String doc, required bool isPossiblyDartCollection, - required String? commonSupertype, - required String? commonSubtype, required ParameterElement? parameterElement, }) : super( name: name, @@ -389,8 +369,6 @@ class CallbackParameter extends Parameter { defaultValueSource: defaultValueSource, doc: doc, isPossiblyDartCollection: isPossiblyDartCollection, - commonSupertype: commonSupertype, - commonSubtype: commonSubtype, parameterElement: parameterElement, ); diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index 6e8133e9..820ea7eb 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -32,8 +32,6 @@ class Property { required this.isDartMap, required this.isDartSet, required this.isPossiblyDartCollection, - required this.commonSupertype, - required this.commonSubtype, }) : type = type ?? 'dynamic'; Property.fromParameter(Parameter p) @@ -51,8 +49,6 @@ class Property { isPossiblyDartCollection: p.isPossiblyDartCollection, // TODO: support hasJsonKey hasJsonKey: false, - commonSupertype: p.commonSupertype, - commonSubtype: p.commonSubtype, ); static Future fromParameterElement( @@ -82,8 +78,6 @@ class Property { defaultValueSource: defaultValue, hasJsonKey: element.hasJsonKey, isPossiblyDartCollection: element.type.isPossiblyDartCollection, - commonSupertype: null, - commonSubtype: null, ); } @@ -99,15 +93,6 @@ class Property { final bool hasJsonKey; final String doc; final bool isPossiblyDartCollection; - final String? commonSupertype; - final String? commonSubtype; - - /// When a property is shared between union cases, this boolean - /// presents whether the union cases define a property within the same name - /// but different type. - /// - /// In that scenario, the abstract class uses a downcasted version of the property. - bool get isDowncastedAsCommonProperty => commonSupertype == commonSubtype; @override String toString() { @@ -117,7 +102,7 @@ class Property { Getter get unimplementedGetter => Getter( name: name, - type: commonSupertype ?? type, + type: type, decorators: decorators, doc: doc, body: ' => throw $privConstUsedErrorVarName;', @@ -141,7 +126,7 @@ class Property { Setter get unimplementedSetter => Setter( name: name, - type: commonSubtype ?? type, + type: type, decorators: decorators, doc: doc, body: ' => throw $privConstUsedErrorVarName;', @@ -168,8 +153,6 @@ class Property { bool? hasJsonKey, String? doc, bool? isPossiblyDartCollection, - String? commonSupertype, - String? commonSubtype, ParameterElement? parameterElement, }) { return Property( @@ -186,8 +169,6 @@ class Property { isDartSet: isDartSet ?? this.isDartSet, isPossiblyDartCollection: isPossiblyDartCollection ?? this.isPossiblyDartCollection, - commonSupertype: commonSupertype ?? this.commonSupertype, - commonSubtype: commonSubtype ?? this.commonSubtype, ); } } diff --git a/packages/freezed/lib/src/templates/prototypes.dart b/packages/freezed/lib/src/templates/prototypes.dart index 404da04b..c2ebfcc3 100644 --- a/packages/freezed/lib/src/templates/prototypes.dart +++ b/packages/freezed/lib/src/templates/prototypes.dart @@ -127,8 +127,6 @@ String _mapPrototype( // TODO: do we want to support freezed classes that implements MapView/ListView? isPossiblyDartCollection: false, showDefaultValue: false, - commonSupertype: null, - commonSubtype: null, parameterElement: null, ), ]); @@ -194,8 +192,6 @@ String _unionPrototype( defaultValueSource: '', doc: '', isPossiblyDartCollection: false, - commonSupertype: null, - commonSubtype: null, parameterElement: null, );