Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [v2.3.1] Invalid copyWith override #818

Closed
zs-dima opened this issue Dec 7, 2022 · 3 comments · Fixed by #819
Closed

[BUG] [v2.3.1] Invalid copyWith override #818

zs-dima opened this issue Dec 7, 2022 · 3 comments · Fixed by #819
Labels
bug Something isn't working needs triage

Comments

@zs-dima
Copy link

zs-dima commented Dec 7, 2022

v2.3.1 still has Invalid copyWith override issue

@freezed
class Union with _$Union {
  factory Union.first(int value) = _UnionFirst;
  factory Union.second(double? value) = _UnionSecond;
  factory Union.third(Syting value) = _UnionThird;
* * *
Error: The parameter 'text' of the method '_$$_SearchTextChangedCopyWith.call' has type 'String', which does not match the corresponding type, 'String?', in the overridden method, '$SearchEventCopyWith.call'.
lib/…/***_bloc.freezed.dart:239
Change to a supertype of 'String?', or, for a covariant parameter, a subtype.
  $Res call({String text});
                    ^
: Context: This is the overridden method ('call').
lib/…/***_bloc.freezed.dart:70
  $Res call({String? text});
       ^
: Error: The parameter 'text' of the method '_$$_SearchTextChangedCopyWith.call' has type 'String', which does not match the corresponding type, 'String?', in the overridden method, '$SearchEventCopyWith.call'.

related issues:
#814
#811

@zs-dima zs-dima added bug Something isn't working needs triage labels Dec 7, 2022
@rrousselGit
Copy link
Owner

Could you share a real example?

Your error doesn't match your example.

@fryette
Copy link

fryette commented Dec 7, 2022

@rrousselGit
Seems I able to reproduce an issue with 2.3.1
@zs-dima example generate normal freezed file without any issues

But after some modifications...

@freezed
class Union with _$Union {
  factory Union.eventOne({
    required int count,
    required String? id,
    required String? name,
  }) = UnionOne;

  factory Union.eventTwo({
    required int? count,
    required String id,
    required String name,
  }) = UnionTwo;
}

It generate not compilable freezed.dart with incorrect override

abstract class _$$UnionTwoCopyWith<$Res> implements $UnionCopyWith<$Res> {
  factory _$$UnionTwoCopyWith(
          _$UnionTwo value, $Res Function(_$UnionTwo) then) =
      __$$UnionTwoCopyWithImpl<$Res>;
  @override
  @useResult
  $Res call({int? count, String id, String name}); // error here
}

_'_$$UnionTwoCopyWith.call' ('$Res Function({int? count, String id, String name})') isn't a valid override of '$UnionCopyWith.call' ('$Res Function({int count, String? id, String? name})')._

Also I still have some issues with nested models, but as far as I see it's related to the same issue that I mentioned above

@rrousselGit rrousselGit linked a pull request Dec 7, 2022 that will close this issue
@rrousselGit
Copy link
Owner

Fixed.

So many edge-cases... At least we're moving forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants