freezed icon indicating copy to clipboard operation
freezed copied to clipboard

Incorrect "The class Foo was declared as abstract, but ..."

Open noinskit opened this issue 1 year ago • 3 comments

Describe the bug I had code with freezed classes that need to be abstract in order to compile, but got a warning at code generation time about this "not being needed anymore".

To Reproduce Example code (the point is to have some property accessible at the Union type, which for some subtypes is always the same and shouldn't be passed to their constructor):

@freezed
abstract class Union with _$Union {
  const factory Union.int(int value) = _Int;

  @With<_HalfMixin>()
  const factory Union.half() = _Half;

  num get value;
}

abstract class _HalfMixin {
  double get value => 0.5;
}

Generated code is working, but it's getting:

The class Union was declared as abstract, but it is not needed anymore.
Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/CHANGELOG.md#0140

Expected behavior No warning in this case and/or a better way to achieve the above.

noinskit avatar Mar 22 '23 13:03 noinskit

Remove the abstract keyword. It's not needed

rrousselGit avatar Mar 26 '23 10:03 rrousselGit

If I remove it, the example does not compile anymore with the error:

'value' must have a method body because 'Union' isn't abstract.
Try making 'Union' abstract, or adding a body to 'value'.

Could you please kindly take a look at the example I provided in this issue?

noinskit avatar Mar 26 '23 11:03 noinskit

I apologize, I misunderstood your description. Thats reasonable then.

rrousselGit avatar Mar 26 '23 18:03 rrousselGit