mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:27:39 +00:00
Correct primitive equality error test
Implicitly induced noSuchMethod forwarders cannot eliminate primitive equality: They are not generated at all if they would override an explicit member declaration (here: `Object.hashCode` and `Object.[]`). Hence, the classes `Secret...` that we used to have (which were intended to do just that) were simply compile-time errors, and hence those classes and the locations where they were used are being removed in this CL. Change-Id: Id1a1f9bc1a2f7ce1886388d6938d0d0a4da45d84 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279394 Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
c8df5570bc
commit
4f8af109af
|
@ -7,6 +7,12 @@
|
|||
// Verify that the use of a constant expression denoting an object that does
|
||||
// not have primitive equality in a constant set or as a key of a constant map
|
||||
// gives rise to a compile-time error.
|
||||
//
|
||||
// An enum cannot override `==` or `hashCode`, hence there are no cases with
|
||||
// enums. Similarly, implicitly induced noSuchMethod forwarders cannot
|
||||
// eliminate primitive equality from a given class: Such forwarders cannot
|
||||
// override an explicitly declared inherited method implementation, in this
|
||||
// case `Object.hashCode` and `Object.[]`.
|
||||
|
||||
class A {
|
||||
const A();
|
||||
|
@ -24,26 +30,6 @@ class C {
|
|||
bool operator ==(Object other) => super == other;
|
||||
}
|
||||
|
||||
// Check that implicitly induced `noSuchMethod` forwarders are detected.
|
||||
|
||||
abstract class WeirdEquals {
|
||||
bool operator ==(Object? other);
|
||||
}
|
||||
|
||||
class SecretNonPrimitiveEquals implements WeirdEquals {
|
||||
noSuchMethod(Invocation invocation) => true;
|
||||
}
|
||||
|
||||
abstract class WeirdHashCode {
|
||||
Never get hashCode;
|
||||
}
|
||||
|
||||
class SecretNonPrimitiveHashCode implements WeirdHashCode {
|
||||
noSuchMethod(Invocation invocation) => 0;
|
||||
}
|
||||
|
||||
// An enum cannot override `==` or `hashCode`, hence no cases with enums.
|
||||
|
||||
const aSet = <Object?>{
|
||||
0.5,
|
||||
//^^^
|
||||
|
@ -64,14 +50,6 @@ const aSet = <Object?>{
|
|||
C(),
|
||||
//^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
SecretNonPrimitiveEquals(),
|
||||
//^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
SecretNonPrimitiveHashCode(),
|
||||
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
(A(), false, 1),
|
||||
//^^^^^^^^^^^^^^^
|
||||
|
@ -99,14 +77,6 @@ const aMap = <Object?, Null>{
|
|||
C(): null,
|
||||
//^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
SecretNonPrimitiveEquals(): null,
|
||||
//^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
SecretNonPrimitiveHashCode(): null,
|
||||
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
(A(), false, 1): null,
|
||||
//^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue