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

When generating == overrides, use Object instead of dynamic #1192

Closed
cadaniel opened this issue May 14, 2021 · 4 comments
Closed

When generating == overrides, use Object instead of dynamic #1192

cadaniel opened this issue May 14, 2021 · 4 comments

Comments

@cadaniel
Copy link

I'm using moor and mockito packages together. I've found a problem where mockito can't fake objects because moor generates the equals operator with dynamic instead of Object.

The generated class for moor uses the following equals operator

@override
  bool operator ==(dynamic other) =>
      identical(this, other) ||
      (other is ExerciseEvent &&
          other.id == this.id &&
          other.eventType == this.eventType &&
          other.description == this.description &&
          other.date == this.date &&
          other.customEvent == this.customEvent &&
          other.customEventName == this.customEventName &&
          other.duration == this.duration &&
          other.distance == this.distance &&
          other.elevationGain == this.elevationGain &&
          other.avgPace == this.avgPace &&
          other.avgSpeed == this.avgSpeed &&
          other.avgPower == this.avgPower &&
          other.avgHR == this.avgHR &&
          other.calories == this.calories &&
          other.cyclePhase == this.cyclePhase &&
          other.lastUpdated == this.lastUpdated &&
          other.delete == this.delete);

Where changing to

@override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is ExerciseEvent &&
          other.id == this.id &&
          other.eventType == this.eventType &&
          other.description == this.description &&
          other.date == this.date &&
          other.customEvent == this.customEvent &&
          other.customEventName == this.customEventName &&
          other.duration == this.duration &&
          other.distance == this.distance &&
          other.elevationGain == this.elevationGain &&
          other.avgPace == this.avgPace &&
          other.avgSpeed == this.avgSpeed &&
          other.avgPower == this.avgPower &&
          other.avgHR == this.avgHR &&
          other.calories == this.calories &&
          other.cyclePhase == this.cyclePhase &&
          other.lastUpdated == this.lastUpdated &&
          other.delete == this.delete);

Allows mock to override the implementation for a proper mock.

@srawlins
Copy link

It does seem weird to me that the argument to operator == is dynamic. I think it should be Object or Object?.

@cadaniel
Copy link
Author

I do agree.

It's what the dart language actually uses

https://api.dart.dev/stable/2.13.0/dart-core/Object/operator_equals.html

But I'm wondering if there's a way I can disable fake generation to allow me use the generator again.

@simolus3
Copy link
Owner

In my defense, it used to be dynamic before the sdk has been migrated to null safety. Obviously Object is a better choice now that should work with and without null safety, I've changed the generated code in 41eb6f4.

@cadaniel
Copy link
Author

Thanks for the quick change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants