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

toString override not working #1120

Open
johnnyggalt opened this issue Aug 23, 2024 · 0 comments
Open

toString override not working #1120

johnnyggalt opened this issue Aug 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@johnnyggalt
Copy link

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

import 'package:freezed_annotation/freezed_annotation.dart';

part 'repro.freezed.dart';

@freezed
class Repro with _$Repro {
  const factory Repro({required int foo}) = _Repro;

  @override
  String toString() => 'My custom toString';
}

void doRepro() {
  const repro = Repro(foo: 42);

  // "Instance of '_$ReproImpl'"
  final reproToString = repro.toString();
}

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:

dependencies:
  freezed_annotation: ^2.4.4

dev_dependencies:
  build_runner: ^2.4.12
  freezed: ^2.5.7
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

No branches or pull requests

2 participants