|
29 | 29 | use PHPStan\Analyser\ExpressionResultStorage; |
30 | 30 | use PHPStan\Analyser\ExpressionTypeHolder; |
31 | 31 | use PHPStan\Analyser\ExprHandler; |
| 32 | +use PHPStan\Analyser\ExprHandler\Helper\MethodThrowPointHelper; |
32 | 33 | use PHPStan\Analyser\ExprHandler\Helper\NonNullabilityHelper; |
33 | 34 | use PHPStan\Analyser\ImpurePoint; |
34 | 35 | use PHPStan\Analyser\InternalThrowPoint; |
@@ -105,6 +106,7 @@ public function __construct( |
105 | 106 | private ArrayDimFetchHandler $arrayDimFetchHandler, |
106 | 107 | private PropertyFetchHandler $propertyFetchHandler, |
107 | 108 | private StaticPropertyFetchHandler $staticPropertyFetchHandler, |
| 109 | + private MethodThrowPointHelper $methodThrowPointHelper, |
108 | 110 | ) |
109 | 111 | { |
110 | 112 | } |
@@ -1080,14 +1082,12 @@ public function applyWrite( |
1080 | 1082 | && !$setVarType->isArray()->yes() |
1081 | 1083 | && !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($setVarType)->no() |
1082 | 1084 | ) { |
1083 | | - $throwPoints = array_merge($throwPoints, $nodeScopeResolver->processExprNode( |
1084 | | - $stmt, |
1085 | | - new MethodCall(new TypeExpr($setVarType), 'offsetSet'), |
| 1085 | + $throwPoints = array_merge($throwPoints, $this->methodThrowPointHelper->getThrowPointsForCallOnType( |
1086 | 1086 | $scope, |
1087 | | - $storage, |
1088 | | - new NoopNodeCallback(), |
1089 | 1087 | $context, |
1090 | | - )->getThrowPoints()); |
| 1088 | + $setVarType, |
| 1089 | + new MethodCall(new TypeExpr($setVarType), 'offsetSet'), |
| 1090 | + )); |
1091 | 1091 | } |
1092 | 1092 | } elseif ($kind === PreparedAssignTarget::KIND_PROPERTY_FETCH) { |
1093 | 1093 | if (!$var instanceof PropertyFetch) { |
@@ -1173,16 +1173,15 @@ public function applyWrite( |
1173 | 1173 | $assignedExprType = $scope->getType($assignedExpr); |
1174 | 1174 | $nodeScopeResolver->callNodeCallback($nodeCallback, new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scopeBeforeAssignEval, $storage); |
1175 | 1175 | $scope = $scope->assignExpression($var, $assignedExprType, $scope->getNativeType($assignedExpr)); |
1176 | | - // simulate dynamic property assign by __set to get throw points |
| 1176 | + // simulate dynamic property assign by __set to get throw points; |
| 1177 | + // the receiver's own throw points were already collected by its walk |
1177 | 1178 | if (!$propertyHolderType->hasMethod('__set')->no()) { |
1178 | | - $throwPoints = array_merge($throwPoints, $nodeScopeResolver->processExprNode( |
1179 | | - $stmt, |
1180 | | - new MethodCall($var->var, '__set'), |
| 1179 | + $throwPoints = array_merge($throwPoints, $this->methodThrowPointHelper->getThrowPointsForCallOnType( |
1181 | 1180 | $scope, |
1182 | | - $storage, |
1183 | | - new NoopNodeCallback(), |
1184 | 1181 | $context, |
1185 | | - )->getThrowPoints()); |
| 1182 | + $propertyHolderType, |
| 1183 | + new MethodCall($var->var, '__set'), |
| 1184 | + )); |
1186 | 1185 | } |
1187 | 1186 | } |
1188 | 1187 |
|
|
0 commit comments