dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

We should probably deprecate DartType.operator== and DartType.hashCode #40507

Open stereotype441 opened 4 years ago

stereotype441 commented 4 years ago

Analyzer clients currently use DartType.operator== (and potentially DartType.hashCode) to compare whether types are the same. This has several disadvantages:

It would be nice if we could deprecate the use of DartType.operator== and DartType.hashCode. Unfortunately we don't have a good way to statically find uses of these. We would have to do something like change their implementations to throw an exception (in a breaking change release of the analyzer, after a suitable warning period), and then use experimental rolls into the internal codebase to detect all clients that need to be fixed.

stereotype441 commented 4 years ago

Another idea: to help clients find places where they use DartType.operator== and DartType.hashCode, we could have a static boolean to control whether they throw an exception. Once a client has stopped using the deprecated logic, it could set the boolean in its tests, to make sure it doesn't accidentally regress later. We could mark the boolean as @visibleForTesting to avoid accidental misuse.

Once all clients have been fixed, we would hardcode the boolean to true (in a breaking change release of the analyzer).