mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:32:49 +00:00
4fc60b20df
Change-Id: Iddb347f05eac14048969eb4e6b05e9eab31532e6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145582 Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Test the dynamic semantics of expressions of the form `e1 == e2` when
|
|
// the `operator ==` parameter is covariant.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class EqNever {
|
|
operator ==(covariant Never other) => throw "unreachable";
|
|
}
|
|
|
|
class EqTypeVar<T extends Object> {
|
|
operator ==(covariant T other) => identical(this, other);
|
|
}
|
|
|
|
void main() {
|
|
Object oNever = EqNever();
|
|
Object oTypeNum = EqTypeVar<num>();
|
|
Object? myNull = null;
|
|
|
|
Expect.isFalse(oNever == null);
|
|
Expect.isFalse(null == oNever);
|
|
Expect.throws(() => oNever == 0);
|
|
Expect.isFalse(0 == oNever);
|
|
Expect.isFalse(oTypeNum == null);
|
|
Expect.isFalse(null == oTypeNum);
|
|
Expect.isFalse(oTypeNum == 0);
|
|
Expect.isFalse(0 == oTypeNum);
|
|
Expect.isFalse(oTypeNum == 0.0);
|
|
Expect.isFalse(0.0 == oTypeNum);
|
|
Expect.throws(() => oTypeNum == "not a number");
|
|
Expect.isFalse("not a number" == oTypeNum);
|
|
Expect.throws(() => oTypeNum == oTypeNum);
|
|
Expect.isFalse(oNever == myNull);
|
|
Expect.isFalse(myNull == oNever);
|
|
Expect.isFalse(oTypeNum == myNull);
|
|
Expect.isFalse(myNull == oTypeNum);
|
|
}
|