-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
toString override not working #1120
Comments
Do you try that this code? @freezed
to
@Freezed(toStringOverride: false) |
@get6 Yes, tried that (I should have mentioned in my issue). It does not make any difference. |
I just circled back to this because I'm shipping to prod shortly, and I've identified a fix. This code does not work: @freezed
class Repro with _$Repro {
const factory Repro({required int foo}) = _Repro;
@override
String toString() => 'My custom toString';
} This code does work: @freezed
class Repro with _$Repro {
Repro._();
const factory Repro({required int foo}) = _Repro;
@override
String toString() => 'My custom toString';
} So for some reason the private constructor is required. |
@johnnyggalt |
Hi, @johnnyggalt https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models |
Yeah, but the explanation doesn't really fit my experience. The problem is that in my example, there is no compile error reported, nor is there a runtime error. Instead, the runtime behavior is not what you'd expect (the override is not called). If there was at least an error message then it wouldn't have caused me so much confusion. |
Describe the bug
Overriding
toString
does not work. I feel like I must be doing something incredibly stupid, but have boiled this down to simplest thing that should work, and it doesn't.To Reproduce
Expected behavior
My
toString
implementation should be invoked, not that of the_$ReproImpl
type. Even the IDE agrees it should be invoking my implementation because go-to-definition jumps there, but nope.This is using latest:
The text was updated successfully, but these errors were encountered: