@@ -1971,6 +1971,11 @@ private function resolveType(Expr $node): Type
1971
1971
}
1972
1972
1973
1973
if ($ node instanceof Expr \NullsafeMethodCall) {
1974
+ $ varType = $ this ->getType ($ node ->var );
1975
+ if (!TypeCombinator::containsNull ($ varType )) {
1976
+ return $ this ->getType (new MethodCall ($ node ->var , $ node ->name , $ node ->args ));
1977
+ }
1978
+
1974
1979
return TypeCombinator::union (
1975
1980
$ this ->filterByTruthyValue (new BinaryOp \NotIdentical ($ node ->var , new ConstFetch (new Name ('null ' ))))
1976
1981
->getType (new MethodCall ($ node ->var , $ node ->name , $ node ->args )),
@@ -2025,6 +2030,11 @@ private function resolveType(Expr $node): Type
2025
2030
}
2026
2031
2027
2032
if ($ node instanceof Expr \NullsafePropertyFetch) {
2033
+ $ varType = $ this ->getType ($ node ->var );
2034
+ if (!TypeCombinator::containsNull ($ varType )) {
2035
+ return $ this ->getType (new PropertyFetch ($ node ->var , $ node ->name ));
2036
+ }
2037
+
2028
2038
return TypeCombinator::union (
2029
2039
$ this ->filterByTruthyValue (new BinaryOp \NotIdentical ($ node ->var , new ConstFetch (new Name ('null ' ))))
2030
2040
->getType (new PropertyFetch ($ node ->var , $ node ->name )),
@@ -2102,30 +2112,35 @@ private function resolveType(Expr $node): Type
2102
2112
return new MixedType ();
2103
2113
}
2104
2114
2105
- private function getNullsafeShortCircuitingType (Expr $ var , Type $ type ): Type
2115
+ private function getNullsafeShortCircuitingType (Expr $ expr , Type $ type ): Type
2106
2116
{
2107
- if ($ var instanceof Expr \NullsafePropertyFetch || $ var instanceof Expr \NullsafeMethodCall) {
2108
- return TypeCombinator::addNull ($ type );
2117
+ if ($ expr instanceof Expr \NullsafePropertyFetch || $ expr instanceof Expr \NullsafeMethodCall) {
2118
+ $ varType = $ this ->getType ($ expr ->var );
2119
+ if (TypeCombinator::containsNull ($ varType )) {
2120
+ return TypeCombinator::addNull ($ type );
2121
+ }
2122
+
2123
+ return $ type ;
2109
2124
}
2110
2125
2111
- if ($ var instanceof Expr \ArrayDimFetch) {
2112
- return $ this ->getNullsafeShortCircuitingType ($ var ->var , $ type );
2126
+ if ($ expr instanceof Expr \ArrayDimFetch) {
2127
+ return $ this ->getNullsafeShortCircuitingType ($ expr ->var , $ type );
2113
2128
}
2114
2129
2115
- if ($ var instanceof PropertyFetch) {
2116
- return $ this ->getNullsafeShortCircuitingType ($ var ->var , $ type );
2130
+ if ($ expr instanceof PropertyFetch) {
2131
+ return $ this ->getNullsafeShortCircuitingType ($ expr ->var , $ type );
2117
2132
}
2118
2133
2119
- if ($ var instanceof Expr \StaticPropertyFetch && $ var ->class instanceof Expr) {
2120
- return $ this ->getNullsafeShortCircuitingType ($ var ->class , $ type );
2134
+ if ($ expr instanceof Expr \StaticPropertyFetch && $ expr ->class instanceof Expr) {
2135
+ return $ this ->getNullsafeShortCircuitingType ($ expr ->class , $ type );
2121
2136
}
2122
2137
2123
- if ($ var instanceof MethodCall) {
2124
- return $ this ->getNullsafeShortCircuitingType ($ var ->var , $ type );
2138
+ if ($ expr instanceof MethodCall) {
2139
+ return $ this ->getNullsafeShortCircuitingType ($ expr ->var , $ type );
2125
2140
}
2126
2141
2127
- if ($ var instanceof Expr \StaticCall && $ var ->class instanceof Expr) {
2128
- return $ this ->getNullsafeShortCircuitingType ($ var ->class , $ type );
2142
+ if ($ expr instanceof Expr \StaticCall && $ expr ->class instanceof Expr) {
2143
+ return $ this ->getNullsafeShortCircuitingType ($ expr ->class , $ type );
2129
2144
}
2130
2145
2131
2146
return $ type ;
0 commit comments