mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
[kernel] Fix record type equivalence
- Increment index to avoid infinite loop when the first named elements in the two record types are equivalent. - Add some test cases for record types. Fixes: https://github.com/dart-lang/sdk/issues/52817 Change-Id: Ifbf3505c74a1f130c9c90ddbb6b1d96d9641e51e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311929 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
b859e00908
commit
be6a560ca1
|
@ -129,18 +129,19 @@ class DartTypeEquivalence implements DartTypeVisitor1<bool, DartType> {
|
|||
}
|
||||
}
|
||||
|
||||
// The named fields of [RecordType]s are supposed to be sorted, so we can
|
||||
// use a linear search to compare them.
|
||||
int nodeIndex = 0;
|
||||
int otherIndex = 0;
|
||||
while (result && nodeIndex < node.named.length) {
|
||||
NamedType nodeNamedType = node.named[nodeIndex];
|
||||
NamedType otherNamedType = other.named[otherIndex];
|
||||
// The named fields of [RecordType]s are supposed to be sorted and we know
|
||||
// there are the same number of named fields, so we can use a linear
|
||||
// search to compare them.
|
||||
int i = 0;
|
||||
while (result && i < node.named.length) {
|
||||
NamedType nodeNamedType = node.named[i];
|
||||
NamedType otherNamedType = other.named[i];
|
||||
if (nodeNamedType.name != otherNamedType.name) {
|
||||
result = false;
|
||||
} else {
|
||||
result = nodeNamedType.type.accept1(this, otherNamedType.type);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -162,6 +162,22 @@ void run() {
|
|||
notEqual("Typedef<Object?>?", "Typedef<dynamic>", equateTopTypes: true);
|
||||
areEqual("Typedef<Object?>?", "Typedef<dynamic>",
|
||||
equateTopTypes: true, ignoreTopLevelNullability: true);
|
||||
|
||||
// Record types.
|
||||
areEqual("(int, bool)", "(int, bool)");
|
||||
notEqual("(int, bool)", "(int?, bool)");
|
||||
notEqual("(int, bool)", "(int, bool?)");
|
||||
notEqual("(int, bool)", "({int i, bool b})");
|
||||
areEqual("({int i, bool b})", "({int i, bool b})");
|
||||
areEqual("({int i, bool b})", "({bool b ,int i})");
|
||||
notEqual("({int i, bool b})", "({int? i, bool b})");
|
||||
notEqual("({int i, bool b})", "({int i, bool? b})");
|
||||
notEqual("({int i, bool b})", "({int n, bool b})");
|
||||
notEqual("({int i, bool b})", "({int i, bool t})");
|
||||
areEqual("(int, {bool b})", "(int, {bool b})");
|
||||
notEqual("(int, {bool b})", "(int?, {bool b})");
|
||||
notEqual("(int, {bool b})", "(int, {bool? b})");
|
||||
notEqual("(int, {bool b})", "(int, {bool t})");
|
||||
}
|
||||
|
||||
void areEqual(String type1, String type2,
|
||||
|
|
Loading…
Reference in a new issue