mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
DartObjectImpl.isIdentical() should compare types.
Change-Id: I6b510351f5703956d77e3cae2dd31490c819f87f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135781 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
3b4e9f6db0
commit
5ec14d6e14
|
@ -516,6 +516,25 @@ class DartObjectImpl implements DartObject {
|
|||
/// the [rightOperand].
|
||||
DartObjectImpl isIdentical2(
|
||||
TypeSystemImpl typeSystem, DartObjectImpl rightOperand) {
|
||||
// Workaround for Flutter `const kIsWeb = identical(0, 0.0)`.
|
||||
if (type.isDartCoreInt && rightOperand.type.isDartCoreDouble) {
|
||||
return DartObjectImpl(
|
||||
typeSystem,
|
||||
typeSystem.typeProvider.boolType,
|
||||
BoolState(
|
||||
toIntValue() == 0 && rightOperand.toDoubleValue() == 0.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!_typeSystem.runtimeTypesEqual(type, rightOperand.type)) {
|
||||
return DartObjectImpl(
|
||||
typeSystem,
|
||||
typeSystem.typeProvider.boolType,
|
||||
BoolState(false),
|
||||
);
|
||||
}
|
||||
|
||||
return DartObjectImpl(
|
||||
typeSystem,
|
||||
typeSystem.typeProvider.boolType,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/src/generated/constant.dart';
|
||||
|
@ -710,6 +711,12 @@ class DartObjectImplTest {
|
|||
_assertIdentical(_boolValue(null), _intValue(null), _intValue(3));
|
||||
}
|
||||
|
||||
void test_identical_intZero_doubleZero() {
|
||||
// Used in Flutter:
|
||||
// const bool kIsWeb = identical(0, 0.0);
|
||||
_assertIdentical(_boolValue(true), _intValue(0), _doubleValue(0.0));
|
||||
}
|
||||
|
||||
void test_identical_list_empty() {
|
||||
_assertIdentical(
|
||||
_boolValue(true),
|
||||
|
@ -718,11 +725,44 @@ class DartObjectImplTest {
|
|||
);
|
||||
}
|
||||
|
||||
void test_identical_list_false() {
|
||||
void test_identical_list_false_differentTypes() {
|
||||
_assertIdentical(
|
||||
_boolValue(false),
|
||||
_listValue(_typeProvider.intType, []),
|
||||
_listValue(_typeProvider.doubleType, []),
|
||||
);
|
||||
}
|
||||
|
||||
void test_identical_list_false_differentValues() {
|
||||
_assertIdentical(_boolValue(false), _listValue(_typeProvider.intType, []),
|
||||
_listValue(_typeProvider.intType, [_intValue(3)]));
|
||||
}
|
||||
|
||||
void test_identical_list_true_equalTypes() {
|
||||
_assertIdentical(
|
||||
_boolValue(true),
|
||||
_listValue(_typeProvider.intType, []),
|
||||
_listValue(_typeProvider.intType, []),
|
||||
);
|
||||
}
|
||||
|
||||
void test_identical_list_true_equalTypesRuntime() {
|
||||
_assertIdentical(
|
||||
_boolValue(true),
|
||||
_listValue(
|
||||
_typeProvider.objectType,
|
||||
[],
|
||||
),
|
||||
_listValue(
|
||||
_typeProvider.futureOrElement.instantiate(
|
||||
typeArguments: [_typeProvider.objectType],
|
||||
nullabilitySuffix: NullabilitySuffix.none,
|
||||
),
|
||||
[],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void test_identical_map_empty() {
|
||||
_assertIdentical(
|
||||
_boolValue(true),
|
||||
|
@ -731,7 +771,7 @@ class DartObjectImplTest {
|
|||
);
|
||||
}
|
||||
|
||||
void test_identical_map_false() {
|
||||
void test_identical_map_false_differentEntries() {
|
||||
_assertIdentical(
|
||||
_boolValue(false),
|
||||
_mapValue(_typeProvider.intType, _typeProvider.intType, []),
|
||||
|
@ -743,6 +783,39 @@ class DartObjectImplTest {
|
|||
);
|
||||
}
|
||||
|
||||
void test_identical_map_false_differentTypes() {
|
||||
_assertIdentical(
|
||||
_boolValue(false),
|
||||
_mapValue(_typeProvider.boolType, _typeProvider.intType, []),
|
||||
_mapValue(_typeProvider.intType, _typeProvider.intType, []),
|
||||
);
|
||||
|
||||
_assertIdentical(
|
||||
_boolValue(false),
|
||||
_mapValue(_typeProvider.intType, _typeProvider.boolType, []),
|
||||
_mapValue(_typeProvider.intType, _typeProvider.intType, []),
|
||||
);
|
||||
}
|
||||
|
||||
void test_identical_map_true_equalTypesRuntime() {
|
||||
_assertIdentical(
|
||||
_boolValue(true),
|
||||
_mapValue(
|
||||
_typeProvider.intType,
|
||||
_typeProvider.objectType,
|
||||
[],
|
||||
),
|
||||
_mapValue(
|
||||
_typeProvider.intType,
|
||||
_typeProvider.futureOrElement.instantiate(
|
||||
typeArguments: [_typeProvider.objectType],
|
||||
nullabilitySuffix: NullabilitySuffix.none,
|
||||
),
|
||||
[],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void test_identical_null() {
|
||||
_assertIdentical(_boolValue(true), _nullValue(), _nullValue());
|
||||
}
|
||||
|
@ -2024,12 +2097,12 @@ class DartObjectImplTest {
|
|||
}
|
||||
|
||||
DartObjectImpl _mapValue(DartType keyType, DartType valueType,
|
||||
List<DartObjectImpl> keyElementPairs) {
|
||||
List<DartObjectImpl> keyValuePairs) {
|
||||
Map<DartObjectImpl, DartObjectImpl> map =
|
||||
<DartObjectImpl, DartObjectImpl>{};
|
||||
int count = keyElementPairs.length;
|
||||
int count = keyValuePairs.length;
|
||||
for (int i = 0; i < count;) {
|
||||
map[keyElementPairs[i++]] = keyElementPairs[i++];
|
||||
map[keyValuePairs[i++]] = keyValuePairs[i++];
|
||||
}
|
||||
return DartObjectImpl(
|
||||
_typeSystem,
|
||||
|
|
Loading…
Reference in a new issue