{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/26703","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/26703/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/26703/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/26703/events","html_url":"https://github.com/dart-lang/sdk/issues/26703","id":160267301,"number":26703,"title":"Optional auto-generation of operator== and hashCode on classes with const constructors","user":{"login":"Hixie","id":551196,"avatar_url":"https://avatars.githubusercontent.com/u/551196?v=3","gravatar_id":"","url":"https://api.github.com/users/Hixie","html_url":"https://github.com/Hixie","followers_url":"https://api.github.com/users/Hixie/followers","following_url":"https://api.github.com/users/Hixie/following{/other_user}","gists_url":"https://api.github.com/users/Hixie/gists{/gist_id}","starred_url":"https://api.github.com/users/Hixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hixie/subscriptions","organizations_url":"https://api.github.com/users/Hixie/orgs","repos_url":"https://api.github.com/users/Hixie/repos","events_url":"https://api.github.com/users/Hixie/events{/privacy}","received_events_url":"https://api.github.com/users/Hixie/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-language","name":"area-language","color":"c7def8"},{"url":"https://api.github.com/repos/dart-lang/sdk/labels/Type:%20enhancement","name":"Type: enhancement","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-06-14T19:45:09Z","updated_at":"2016-06-17T06:10:00Z","closed_at":null,"body":"It is a common Dart idiom to have a class with all-final fields, a const constructor, a toString, an operator==, and a hashCode function.\r\n\r\nThe latter two are boilerplate:\r\n```dart\r\n  @override\r\n  bool operator ==(dynamic other) {\r\n    if (other.runtimeType != runtimeType)\r\n      return false;\r\n    final T typedOther = other;\r\n    return typedOther.field1 == field1\r\n        && typedOther.field2 == field2\r\n        && typedOther.fieldN == fieldN;\r\n  }\r\n\r\n  @override\r\n  int get hashCode => hashValues(field1, field2, fieldN);\r\n```\r\n\r\nIt would be nice if there was some syntax or shorthand we could provide that would automatically provide these.\r\n\r\ncc @abarth"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/226688243","html_url":"https://github.com/dart-lang/sdk/issues/26703#issuecomment-226688243","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/26703","id":226688243,"user":{"login":"Hixie","id":551196,"avatar_url":"https://avatars.githubusercontent.com/u/551196?v=3","gravatar_id":"","url":"https://api.github.com/users/Hixie","html_url":"https://github.com/Hixie","followers_url":"https://api.github.com/users/Hixie/followers","following_url":"https://api.github.com/users/Hixie/following{/other_user}","gists_url":"https://api.github.com/users/Hixie/gists{/gist_id}","starred_url":"https://api.github.com/users/Hixie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hixie/subscriptions","organizations_url":"https://api.github.com/users/Hixie/orgs","repos_url":"https://api.github.com/users/Hixie/repos","events_url":"https://api.github.com/users/Hixie/events{/privacy}","received_events_url":"https://api.github.com/users/Hixie/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T06:10:00Z","updated_at":"2016-06-17T06:10:00Z","body":"Incidentally, in Flutter's codebase we sometimes check for type equality using `is` and sometimes using `runtimeType`. There are some specific cases where `is` is the right answer because we want the Liskov substitution principle to apply (e.g. `_DebugSize` vs `Size`) but usually we actually want `runtimeType` equality. I've been slowly moving us towards the latter, but there's lots of cases where we still use the former because we didn't know better when we last did our big pass at making our `operator ==`s consistent.\r\n\r\nThe reason you want to use `operator ==` is that otherwise `foo == bar` might give a different result than `bar == foo` (in particular in the case where `foo` is an instance of a subclass of the class `bar` is an instance of, and `foo`'s class introduces new fields, `foo == bar` might be false even when `bar == foo` is true)."}}
{"actor":{"display_login":"Hixie"}}