@@ -25,6 +25,7 @@ import 'package:analyzer/src/dart/element/subtype.dart';
25
25
import 'package:analyzer/src/dart/element/top_merge.dart' ;
26
26
import 'package:analyzer/src/dart/element/type.dart' ;
27
27
import 'package:analyzer/src/dart/element/type_algebra.dart' ;
28
+ import 'package:analyzer/src/dart/element/type_provider.dart' ;
28
29
import 'package:analyzer/src/dart/element/type_schema.dart' ;
29
30
import 'package:analyzer/src/dart/element/type_schema_elimination.dart' ;
30
31
import 'package:meta/meta.dart' ;
@@ -424,7 +425,7 @@ class TypeSystemImpl extends TypeSystem2 {
424
425
bool strictInference;
425
426
426
427
@override
427
- final TypeProvider typeProvider;
428
+ final TypeProviderImpl typeProvider;
428
429
429
430
/// The cached instance of `Object?` .
430
431
InterfaceTypeImpl _objectQuestion;
@@ -448,8 +449,9 @@ class TypeSystemImpl extends TypeSystem2 {
448
449
@required this .implicitCasts,
449
450
@required bool isNonNullableByDefault,
450
451
@required this .strictInference,
451
- @required this .typeProvider,
452
- }) : super (isNonNullableByDefault: isNonNullableByDefault) {
452
+ @required TypeProvider typeProvider,
453
+ }) : typeProvider = typeProvider as TypeProviderImpl ,
454
+ super (isNonNullableByDefault: isNonNullableByDefault) {
453
455
_greatestLowerBoundHelper = GreatestLowerBoundHelper (this );
454
456
_leastUpperBoundHelper = LeastUpperBoundHelper (this );
455
457
_subtypeHelper = SubtypeHelper (this );
@@ -1591,29 +1593,26 @@ class TypeSystemImpl extends TypeSystem2 {
1591
1593
var t = targetType;
1592
1594
assert (! t.isBottom);
1593
1595
var numType = typeProvider.numType;
1594
- var numTypeQuestion = makeNullable (numType as InterfaceTypeImpl );
1595
- if (isSubtypeOf (t, numTypeQuestion)) {
1596
+ if (isSubtypeOf (t, typeProvider.numTypeQuestion)) {
1596
1597
// Then:
1597
1598
// - If int <: C, not num <: C, and T <: int, then the context type of
1598
1599
// e2 is int.
1599
1600
// (Note: as above, we check the type of T against `int?`, because it's
1600
1601
// equivalent and leads to better error recovery.)
1601
1602
var intType = typeProvider.intType;
1602
- var intTypeQuestion = makeNullable (intType as InterfaceTypeImpl );
1603
1603
if (isSubtypeOf (intType, c) &&
1604
1604
! isSubtypeOf (numType, c) &&
1605
- isSubtypeOf (t, intTypeQuestion)) {
1605
+ isSubtypeOf (t, typeProvider. intTypeQuestion)) {
1606
1606
return intType;
1607
1607
}
1608
1608
// - If double <: C, not num <: C, and not T <: double, then the context
1609
1609
// type of e2 is double.
1610
1610
// (Note: as above, we check the type of T against `double?`, because
1611
1611
// it's equivalent and leads to better error recovery.)
1612
1612
var doubleType = typeProvider.doubleType;
1613
- var doubleTypeQuestion = makeNullable (doubleType as InterfaceTypeImpl );
1614
1613
if (isSubtypeOf (doubleType, c) &&
1615
1614
! isSubtypeOf (numType, c) &&
1616
- ! isSubtypeOf (t, doubleTypeQuestion)) {
1615
+ ! isSubtypeOf (t, typeProvider. doubleTypeQuestion)) {
1617
1616
return doubleType;
1618
1617
}
1619
1618
// Otherwise, the context type of e2 is num.
@@ -1638,27 +1637,24 @@ class TypeSystemImpl extends TypeSystem2 {
1638
1637
var t = targetType;
1639
1638
assert (! t.isBottom);
1640
1639
var numType = typeProvider.numType;
1641
- var numTypeQuestion = makeNullable (numType as InterfaceTypeImpl );
1642
- if (isSubtypeOf (t, numTypeQuestion)) {
1640
+ if (isSubtypeOf (t, typeProvider.numTypeQuestion)) {
1643
1641
// Then:
1644
1642
// - If int <: C, not num <: C, and T <: int, then the context type of
1645
1643
// e2 and e3 is int.
1646
1644
// (Note: as above, we check the type of T against `int?`, because it's
1647
1645
// equivalent and leads to better error recovery.)
1648
1646
var intType = typeProvider.intType;
1649
- var intTypeQuestion = makeNullable (intType as InterfaceTypeImpl );
1650
1647
if (isSubtypeOf (intType, c) &&
1651
1648
! isSubtypeOf (numType, c) &&
1652
- isSubtypeOf (t, intTypeQuestion)) {
1649
+ isSubtypeOf (t, typeProvider. intTypeQuestion)) {
1653
1650
return intType;
1654
1651
}
1655
1652
// - If double <: C, not num <: C, and T <: double, then the context
1656
1653
// type of e2 and e3 is double.
1657
1654
var doubleType = typeProvider.doubleType;
1658
- var doubleTypeQuestion = makeNullable (doubleType as InterfaceTypeImpl );
1659
1655
if (isSubtypeOf (doubleType, c) &&
1660
1656
! isSubtypeOf (numType, c) &&
1661
- isSubtypeOf (t, doubleTypeQuestion)) {
1657
+ isSubtypeOf (t, typeProvider. doubleTypeQuestion)) {
1662
1658
return doubleType;
1663
1659
}
1664
1660
// - Otherwise the context type of e2 an e3 is num.
@@ -1695,9 +1691,7 @@ class TypeSystemImpl extends TypeSystem2 {
1695
1691
// `int? + int` to resolve to `int` rather than `num`).
1696
1692
var t = targetType;
1697
1693
assert (! t.isBottom);
1698
- var numType = typeProvider.numType;
1699
- var numTypeQuestion = makeNullable (numType as InterfaceTypeImpl );
1700
- if (isSubtypeOf (t, numTypeQuestion)) {
1694
+ if (isSubtypeOf (t, typeProvider.numTypeQuestion)) {
1701
1695
// ...and where the static type of e2 is S and S is assignable to num.
1702
1696
// (Note: we don't have to check that S is assignable to num because
1703
1697
// this is required by the signature of the method.)
@@ -1709,8 +1703,7 @@ class TypeSystemImpl extends TypeSystem2 {
1709
1703
// (Note: as above, we check against `double?` because it's equivalent
1710
1704
// and leads to better error recovery.)
1711
1705
var doubleType = typeProvider.doubleType;
1712
- var doubleTypeQuestion =
1713
- makeNullable (doubleType as InterfaceTypeImpl );
1706
+ var doubleTypeQuestion = typeProvider.doubleTypeQuestion;
1714
1707
if (isSubtypeOf (t, doubleTypeQuestion)) {
1715
1708
return doubleType;
1716
1709
}
@@ -1723,15 +1716,14 @@ class TypeSystemImpl extends TypeSystem2 {
1723
1716
// - If T <: int, S <: int and not S <: Never, then the static type of
1724
1717
// e is int.
1725
1718
// (As above, we check against `int?` for error recovery.)
1726
- var intType = typeProvider.intType;
1727
- var intTypeQuestion = makeNullable (intType as InterfaceTypeImpl );
1719
+ var intTypeQuestion = typeProvider.intTypeQuestion;
1728
1720
if (! s.isBottom &&
1729
1721
isSubtypeOf (t, intTypeQuestion) &&
1730
1722
isSubtypeOf (s, intTypeQuestion)) {
1731
- return intType;
1723
+ return typeProvider. intType;
1732
1724
}
1733
1725
// - Otherwise the static type of e is num.
1734
- return numType;
1726
+ return typeProvider. numType;
1735
1727
}
1736
1728
}
1737
1729
}
@@ -1755,8 +1747,7 @@ class TypeSystemImpl extends TypeSystem2 {
1755
1747
// `int?.clamp(int, int)` to resolve to `int` rather than `num`).
1756
1748
// - We don't check that T2 and T3 are subtypes of num because the
1757
1749
// signature of `num.clamp` requires it.
1758
- var numType = typeProvider.numType;
1759
- var numTypeQuestion = makeNullable (numType as InterfaceTypeImpl );
1750
+ var numTypeQuestion = typeProvider.numTypeQuestion;
1760
1751
if (isSubtypeOf (t1, numTypeQuestion) && ! t2.isBottom && ! t3.isBottom) {
1761
1752
assert (! t1.isBottom);
1762
1753
assert (isSubtypeOf (t2, numTypeQuestion));
@@ -1766,26 +1757,23 @@ class TypeSystemImpl extends TypeSystem2 {
1766
1757
// int.
1767
1758
// (Note: as above, we check against `int?` because it's equivalent
1768
1759
// and leads to better error recovery.)
1769
- var intType = typeProvider.intType;
1770
- var intTypeQuestion = makeNullable (intType as InterfaceTypeImpl );
1760
+ var intTypeQuestion = typeProvider.intTypeQuestion;
1771
1761
if (isSubtypeOf (t1, intTypeQuestion) &&
1772
1762
isSubtypeOf (t2, intTypeQuestion) &&
1773
1763
isSubtypeOf (t3, intTypeQuestion)) {
1774
- return intType;
1764
+ return typeProvider. intType;
1775
1765
}
1776
1766
// If T1, T2 and T3 are all subtypes of double, the static type of e
1777
1767
// is double.
1778
1768
// (As above, we check against `double?` for error recovery.)
1779
- var doubleType = typeProvider.doubleType;
1780
- var doubleTypeQuestion =
1781
- makeNullable (doubleType as InterfaceTypeImpl );
1769
+ var doubleTypeQuestion = typeProvider.doubleTypeQuestion;
1782
1770
if (isSubtypeOf (t1, doubleTypeQuestion) &&
1783
1771
isSubtypeOf (t2, doubleTypeQuestion) &&
1784
1772
isSubtypeOf (t3, doubleTypeQuestion)) {
1785
- return doubleType;
1773
+ return typeProvider. doubleType;
1786
1774
}
1787
1775
// Otherwise the static type of e is num.
1788
- return numType;
1776
+ return typeProvider. numType;
1789
1777
}
1790
1778
}
1791
1779
}
0 commit comments