-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathconstant_objects_t01.dart
40 lines (34 loc) · 1.22 KB
/
constant_objects_t01.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2011, 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.
/// @assertion The predefined Dart function identical() is defined such that
/// identical(c1, c2) iff:
/// • c1 and c2 are constant objects of the same class C and each member field
/// of c1 is identical to the corresponding field of c2.
/// @description Checks that identical() works as described even if the classes
/// being compared have operator == redefined to return counter-intuitive result.
/// @author rodionov
/// @issue 42224
import "../../../Utils/expect.dart";
class C {
final x;
const C(this.x);
bool operator ==(Object other) {
if (other is C) {
return this.x != other.x;
}
return true;
}
}
main() {
Expect.isFalse(const C(1) == const C(1));
Expect.isTrue(identical(const C(1), const C(1)));
Expect.isTrue(const C(1) == const C(2));
Expect.isFalse(identical(const C(1), const C(2)));
Expect.isFalse(double.nan == double.nan);
if (isJS) {
Expect.isFalse(identical(double.nan, double.nan));
} else {
Expect.isTrue(identical(double.nan, double.nan));
}
}