@@ -1007,56 +1007,6 @@ private function resolveType(Expr $node): Type
1007
1007
return IntegerRangeType::fromInterval (-1 , 1 );
1008
1008
}
1009
1009
1010
- if ($ node instanceof Expr \AssignOp \Coalesce) {
1011
- return $ this ->getType (new BinaryOp \Coalesce ($ node ->var , $ node ->expr , $ node ->getAttributes ()));
1012
- }
1013
-
1014
- if ($ node instanceof Expr \BinaryOp \Coalesce) {
1015
- if ($ node ->left instanceof Expr \ArrayDimFetch && $ node ->left ->dim !== null ) {
1016
- $ dimType = $ this ->getType ($ node ->left ->dim );
1017
- $ varType = $ this ->getType ($ node ->left ->var );
1018
- $ hasOffset = $ varType ->hasOffsetValueType ($ dimType );
1019
- $ leftType = $ this ->getType ($ node ->left );
1020
- $ rightType = $ this ->getType ($ node ->right );
1021
- if ($ hasOffset ->no ()) {
1022
- return $ rightType ;
1023
- } elseif ($ hasOffset ->yes ()) {
1024
- $ offsetValueType = $ varType ->getOffsetValueType ($ dimType );
1025
- if ($ offsetValueType ->isSuperTypeOf (new NullType ())->no ()) {
1026
- return TypeCombinator::removeNull ($ leftType );
1027
- }
1028
- }
1029
-
1030
- return TypeCombinator::union (
1031
- TypeCombinator::removeNull ($ leftType ),
1032
- $ rightType
1033
- );
1034
- }
1035
-
1036
- $ leftType = $ this ->getType ($ node ->left );
1037
- $ rightType = $ this ->getType ($ node ->right );
1038
- if ($ leftType instanceof ErrorType || $ leftType instanceof NullType) {
1039
- return $ rightType ;
1040
- }
1041
-
1042
- if (
1043
- TypeCombinator::containsNull ($ leftType )
1044
- || $ node ->left instanceof PropertyFetch
1045
- || (
1046
- $ node ->left instanceof Variable
1047
- && is_string ($ node ->left ->name )
1048
- && !$ this ->hasVariableType ($ node ->left ->name )->yes ()
1049
- )
1050
- ) {
1051
- return TypeCombinator::union (
1052
- TypeCombinator::removeNull ($ leftType ),
1053
- $ rightType
1054
- );
1055
- }
1056
-
1057
- return TypeCombinator::removeNull ($ leftType );
1058
- }
1059
-
1060
1010
if ($ node instanceof Expr \Clone_) {
1061
1011
return $ this ->getType ($ node ->expr );
1062
1012
}
@@ -1663,6 +1613,56 @@ private function resolveType(Expr $node): Type
1663
1613
return $ this ->moreSpecificTypes [$ exprString ]->getType ();
1664
1614
}
1665
1615
1616
+ if ($ node instanceof Expr \AssignOp \Coalesce) {
1617
+ return $ this ->getType (new BinaryOp \Coalesce ($ node ->var , $ node ->expr , $ node ->getAttributes ()));
1618
+ }
1619
+
1620
+ if ($ node instanceof Expr \BinaryOp \Coalesce) {
1621
+ if ($ node ->left instanceof Expr \ArrayDimFetch && $ node ->left ->dim !== null ) {
1622
+ $ dimType = $ this ->getType ($ node ->left ->dim );
1623
+ $ varType = $ this ->getType ($ node ->left ->var );
1624
+ $ hasOffset = $ varType ->hasOffsetValueType ($ dimType );
1625
+ $ leftType = $ this ->getType ($ node ->left );
1626
+ $ rightType = $ this ->getType ($ node ->right );
1627
+ if ($ hasOffset ->no ()) {
1628
+ return $ rightType ;
1629
+ } elseif ($ hasOffset ->yes ()) {
1630
+ $ offsetValueType = $ varType ->getOffsetValueType ($ dimType );
1631
+ if ($ offsetValueType ->isSuperTypeOf (new NullType ())->no ()) {
1632
+ return TypeCombinator::removeNull ($ leftType );
1633
+ }
1634
+ }
1635
+
1636
+ return TypeCombinator::union (
1637
+ TypeCombinator::removeNull ($ leftType ),
1638
+ $ rightType
1639
+ );
1640
+ }
1641
+
1642
+ $ leftType = $ this ->getType ($ node ->left );
1643
+ $ rightType = $ this ->getType ($ node ->right );
1644
+ if ($ leftType instanceof ErrorType || $ leftType instanceof NullType) {
1645
+ return $ rightType ;
1646
+ }
1647
+
1648
+ if (
1649
+ TypeCombinator::containsNull ($ leftType )
1650
+ || $ node ->left instanceof PropertyFetch
1651
+ || (
1652
+ $ node ->left instanceof Variable
1653
+ && is_string ($ node ->left ->name )
1654
+ && !$ this ->hasVariableType ($ node ->left ->name )->yes ()
1655
+ )
1656
+ ) {
1657
+ return TypeCombinator::union (
1658
+ TypeCombinator::removeNull ($ leftType ),
1659
+ $ rightType
1660
+ );
1661
+ }
1662
+
1663
+ return TypeCombinator::removeNull ($ leftType );
1664
+ }
1665
+
1666
1666
if ($ node instanceof ConstFetch) {
1667
1667
$ constName = (string ) $ node ->name ;
1668
1668
$ loweredConstName = strtolower ($ constName );
0 commit comments