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

Make operator == override parameters non-nullable #677

Merged
merged 4 commits into from
Feb 7, 2023

Conversation

srawlins
Copy link
Contributor

Make operator == override parameters non-nullable. See dart-lang/linter#3441

Work towards dart-lang/sdk#51038.

@srawlins
Copy link
Contributor Author

I'd love to see those CI failure details.

runtimeType == other.runtimeType &&
characteristicId == other.characteristicId &&
serviceId == other.serviceId;
characteristicId == (other as DiscoveredCharacteristic).characteristicId &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some technical debt here, as this cast could fail at runtime. But I am only here to make a no-op change, and not change behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srawlins I came to the same conclusion here.

What if you did

@override
bool operator ==(Object other) {
  return other is DiscoveredCharacteristic &&
    runtimeType == other.runtimeType &&
    characteristicId == other. characteristicId &&
    serviceId == other. serviceId;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the change I would want to make at some point if I owned the code.

This would be a behavior-changing change, which I am not very comfortable making. x.runtime == y.runtime is different from x == Y. I don't know what subtypes there are, or where exception catching happens and if specific exceptions are caught here or there. I don't want to land a change that is then rolled back because of the changes unrelated to correcting the static analysis issue.

All that being said, I can make your suggested change if you would really like me to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, now that I can see the static analysis issues, it looks like I must make the suggested change, to avoid test_types_in_equals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -31,9 +31,9 @@ class QualifiedCharacteristic {
deviceId.hashCode;

@override
bool operator ==(dynamic other) =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here:

@override
bool operator ==(Object other) {
  return other is QualifiedCharacteristic &&
    runtimeType == other.runtimeType &&
    characteristicId == other. characteristicId &&
    serviceId == other. serviceId && deviceId == other. deviceId;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -68,9 +68,9 @@ class Uuid {
data.fold(17, (hash, octet) => 37 * hash + octet.hashCode);

@override
bool operator ==(dynamic other) =>
bool operator ==(Object other) =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here:

@override
bool operator ==(Object other) {
  return other is Uuid && other.runtimeType == runtimeType &&
   const DeepCollectionEquality().equals(other.data, data);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Taym95
Copy link
Collaborator

Taym95 commented Jan 18, 2023

@srawlins

[reactive_ble_platform_interface]: 
[reactive_ble_platform_interface]: 
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/discovered_characteristic.dart:43:28 • test_types_in_equals
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/discovered_characteristic.dart:44:21 • test_types_in_equals
[reactive_ble_platform_interface]:    info • Unnecessary cast • lib/src/model/discovered_characteristic.dart:44:21 • unnecessary_cast
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/qualified_characteristic.dart:36:28 • test_types_in_equals
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/qualified_characteristic.dart:37:21 • test_types_in_equals
[reactive_ble_platform_interface]:    info • Unnecessary cast • lib/src/model/qualified_characteristic.dart:37:21 • unnecessary_cast
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/qualified_characteristic.dart:38:20 • test_types_in_equals
[reactive_ble_platform_interface]:    info • Unnecessary cast • lib/src/model/qualified_characteristic.dart:38:20 • unnecessary_cast
[reactive_ble_platform_interface]:    info • Test type arguments in operator ==(Object other) • lib/src/model/uuid.dart:73:46 • test_types_in_equals
[reactive_ble_platform_interface]: 
[reactive_ble_platform_interface]: 9 issues found. (ran in 1.3s)

You dont need CI, you can check it locally with melos

@srawlins
Copy link
Contributor Author

Ready for review

return other is Uuid &&
other.runtimeType == runtimeType &&
const DeepCollectionEquality().equals(other.data, data);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still failing, please check quality locally:

$ melos exec
  └> flutter analyze
     └> FAILED (in 1 packages)
        └> reactive_ble_platform_interface (with exit code 1)

melos run analyze
  └> melos exec -- flutter analyze
     └> FAILED
ScriptException: The script analyze failed to execute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, complete.

@srawlins
Copy link
Contributor Author

Ready for review

1 similar comment
@srawlins
Copy link
Contributor Author

srawlins commented Feb 6, 2023

Ready for review

@Taym95 Taym95 merged commit e14d8d0 into PhilipsHue:master Feb 7, 2023
@srawlins srawlins deleted the nullable-equals branch February 7, 2023 15:19
@srawlins
Copy link
Contributor Author

srawlins commented Feb 7, 2023

Thank you!

Taym95 pushed a commit that referenced this pull request Jul 6, 2023
* Make operator == override parameters no-nullable. See dart-lang/linter#3441

Work towards dart-lang/sdk#51038.
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

Successfully merging this pull request may close these issues.

None yet

3 participants