Skip to content

Commit e77f2ee

Browse files
chloestefantsovaCommit Queue
authored and
Commit Queue
committed
[cfe] Account for class Record in constraint gathering
Part of #49713 Change-Id: Idfcc304c8da8bb1a6cd887de707ddfd060934543 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262427 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent e860cf2 commit e77f2ee

9 files changed

+80
-2
lines changed

pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,14 @@ abstract class TypeConstraintGatherer {
834834
_protoConstraints.length = baseConstraintCount;
835835
}
836836

837+
// A type P is a subtype match for Record with respect to L under no
838+
// constraints:
839+
//
840+
// If P is a record type or Record.
841+
if (q == coreTypes.recordNonNullableRawType && p is RecordType) {
842+
return true;
843+
}
844+
837845
// A record type `(M0,..., Mk, {M{k+1} d{k+1}, ..., Mm dm])` is a subtype
838846
// match for a record type `(N0,..., Nk, {N{k+1} d{k+1}, ..., Nm dm])` with
839847
// respect to `L` under constraints `C0 + ... + Cm`

pkg/front_end/testcases/records/simple_inference.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ class A9<X extends (Y, Z), Y extends num, Z extends String?> {}
3838

3939
foo9(A9 a) {}
4040

41+
class A10<X, Y> {}
42+
43+
A10<(T, T), T> foo10<T>() => throw 0;
44+
45+
bar10() {
46+
A10<Record, String> r = foo10();
47+
}
48+
49+
4150
main() {}

pkg/front_end/testcases/records/simple_inference.dart.strong.expect

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1212
: super core::Object::•()
1313
;
1414
}
15+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
16+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
17+
: super core::Object::•()
18+
;
19+
}
1520
static method foo1((core::int, core::String?) r) → dynamic {
1621
(core::int, core::String?) r2 = r;
1722
}
@@ -37,4 +42,9 @@ static method foo7(<X extends core::Object? = dynamic, Y extends core::Object? =
3742
}
3843
static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic {}
3944
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic {}
45+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
46+
return throw 0;
47+
static method bar10() → dynamic {
48+
self::A10<core::Record, core::String> r = self::foo10<core::String>();
49+
}
4050
static method main() → dynamic {}

pkg/front_end/testcases/records/simple_inference.dart.strong.transformed.expect

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1212
: super core::Object::•()
1313
;
1414
}
15+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
16+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
17+
: super core::Object::•()
18+
;
19+
}
1520
static method foo1((core::int, core::String?) r) → dynamic {
1621
(core::int, core::String?) r2 = r;
1722
}
@@ -37,6 +42,11 @@ static method foo7(<X extends core::Object? = dynamic, Y extends core::Object? =
3742
}
3843
static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic {}
3944
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic {}
45+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
46+
return throw 0;
47+
static method bar10() → dynamic {
48+
self::A10<core::Record, core::String> r = self::foo10<core::String>();
49+
}
4050
static method main() → dynamic {}
4151

4252

@@ -45,4 +55,4 @@ Evaluated: RecordLiteral @ org-dartlang-testcase:///simple_inference.dart:14:18
4555
Evaluated: VariableGetImpl @ org-dartlang-testcase:///simple_inference.dart:14:18 -> RecordConstant(const (3, 3.5))
4656
Evaluated: VariableGet @ org-dartlang-testcase:///simple_inference.dart:14:18 -> RecordConstant(const (3, 3.5))
4757
Evaluated: RecordLiteral @ org-dartlang-testcase:///simple_inference.dart:18:18 -> RecordConstant(const (3, 3.5))
48-
Extra constant evaluation: evaluated: 25, effectively constant: 4
58+
Extra constant evaluation: evaluated: 27, effectively constant: 4

pkg/front_end/testcases/records/simple_inference.dart.textual_outline.expect

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ class A8<X extends (X, Y), Y extends num> {}
99
foo8(A8 a) {}
1010
class A9<X extends (Y, Z), Y extends num, Z extends String?> {}
1111
foo9(A9 a) {}
12+
class A10<X, Y> {}
13+
A10<(T, T), T> foo10<T>() => throw 0;
14+
bar10() {}
1215
main() {}

pkg/front_end/testcases/records/simple_inference.dart.weak.expect

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1212
: super core::Object::•()
1313
;
1414
}
15+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
16+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
17+
: super core::Object::•()
18+
;
19+
}
1520
static method foo1((core::int, core::String?) r) → dynamic {
1621
(core::int, core::String?) r2 = r;
1722
}
@@ -37,4 +42,9 @@ static method foo7(<X extends core::Object? = dynamic, Y extends core::Object? =
3742
}
3843
static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic {}
3944
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic {}
45+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
46+
return throw 0;
47+
static method bar10() → dynamic {
48+
self::A10<core::Record, core::String> r = self::foo10<core::String>();
49+
}
4050
static method main() → dynamic {}

pkg/front_end/testcases/records/simple_inference.dart.weak.modular.expect

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1212
: super core::Object::•()
1313
;
1414
}
15+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
16+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
17+
: super core::Object::•()
18+
;
19+
}
1520
static method foo1((core::int, core::String?) r) → dynamic {
1621
(core::int, core::String?) r2 = r;
1722
}
@@ -37,4 +42,9 @@ static method foo7(<X extends core::Object? = dynamic, Y extends core::Object? =
3742
}
3843
static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic {}
3944
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic {}
45+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
46+
return throw 0;
47+
static method bar10() → dynamic {
48+
self::A10<core::Record, core::String> r = self::foo10<core::String>();
49+
}
4050
static method main() → dynamic {}

pkg/front_end/testcases/records/simple_inference.dart.weak.outline.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1010
synthetic constructor •() → self::A9<self::A9::X, self::A9::Y, self::A9::Z%>
1111
;
1212
}
13+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
14+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
15+
;
16+
}
1317
static method foo1((core::int, core::String?) r) → dynamic
1418
;
1519
static method foo2((core::int, core::String?) r, <X extends core::Object? = dynamic>() → X% f) → dynamic
@@ -28,5 +32,9 @@ static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic
2832
;
2933
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic
3034
;
35+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
36+
;
37+
static method bar10() → dynamic
38+
;
3139
static method main() → dynamic
3240
;

pkg/front_end/testcases/records/simple_inference.dart.weak.transformed.expect

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class A9<X extends (self::A9::Y, self::A9::Z%) = (core::num, core::String?), Y e
1212
: super core::Object::•()
1313
;
1414
}
15+
class A10<X extends core::Object? = dynamic, Y extends core::Object? = dynamic> extends core::Object {
16+
synthetic constructor •() → self::A10<self::A10::X%, self::A10::Y%>
17+
: super core::Object::•()
18+
;
19+
}
1520
static method foo1((core::int, core::String?) r) → dynamic {
1621
(core::int, core::String?) r2 = r;
1722
}
@@ -37,6 +42,11 @@ static method foo7(<X extends core::Object? = dynamic, Y extends core::Object? =
3742
}
3843
static method foo8(self::A8<(dynamic, core::num), core::num> a) → dynamic {}
3944
static method foo9(self::A9<(core::num, core::String?), core::num, core::String?> a) → dynamic {}
45+
static method foo10<T extends core::Object? = dynamic>() → self::A10<(self::foo10::T%, self::foo10::T%), self::foo10::T%>
46+
return throw 0;
47+
static method bar10() → dynamic {
48+
self::A10<core::Record, core::String> r = self::foo10<core::String>();
49+
}
4050
static method main() → dynamic {}
4151

4252

@@ -45,4 +55,4 @@ Evaluated: RecordLiteral @ org-dartlang-testcase:///simple_inference.dart:14:18
4555
Evaluated: VariableGetImpl @ org-dartlang-testcase:///simple_inference.dart:14:18 -> RecordConstant(const (3, 3.5))
4656
Evaluated: VariableGet @ org-dartlang-testcase:///simple_inference.dart:14:18 -> RecordConstant(const (3, 3.5))
4757
Evaluated: RecordLiteral @ org-dartlang-testcase:///simple_inference.dart:18:18 -> RecordConstant(const (3, 3.5))
48-
Extra constant evaluation: evaluated: 25, effectively constant: 4
58+
Extra constant evaluation: evaluated: 27, effectively constant: 4

0 commit comments

Comments
 (0)