xsahil03x / super_enum

Create super-powered dart enums similar to sealed classes in Kotlin
https://pub.dev/packages/super_enum
MIT License
116 stars 13 forks source link

@object enum values generated as: List get props =>null #26

Closed WanderingFire2001 closed 4 years ago

WanderingFire2001 commented 4 years ago

A consequence of generating List get props => null; is that (with the current Equatable package: equatable 1.0.1), calling hashCode on a generated @object throws NoSuchMethodError.

To reproduce:

import 'package:super_enum/super_enum.dart';
part "my_state.g.dart";

@superEnum
enum _MyState {
  @object
  Success,
  @object
  Error,
}
...
  // any running code
  var success = MyState.success();
  success.hashCode;

**BOOM! NoSuchMethodError: The method 'fold' was called on null. Receiver: null Tried calling: fold(0, Closure: (int, dynamic) => i**

I got bit pretty hard by this tonight, in test code checking emitsInOrder on a StreamController, but hashCode is called in plenty of situations.

The bug arises because the generator produces

List get props => null;

Instead the generator needs to produce:

List get props => const [];

I see you have an outstanding pull request on an unrelated issue that silently fixes this: https://github.com/xsahil03x/super_enum/pull/23

(small nit: that fix assigns props [] and not const []).

Not knowing the timeline for that PR, I wanted to raise this as a separate (and urgent) issue.

xsahil03x commented 4 years ago

@WanderingFire2001 thanks for mentioning, fixed in #23