@@ -1231,8 +1231,13 @@ private function ensureNonNullability(MutatingScope $scope, Expr $expr, bool $fi
1231
1231
$ exprType = $ scope ->getType ($ exprToSpecify );
1232
1232
$ exprTypeWithoutNull = TypeCombinator::removeNull ($ exprType );
1233
1233
if (!$ exprType ->equals ($ exprTypeWithoutNull )) {
1234
- $ specifiedExpressions [] = new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType );
1235
- $ scope = $ scope ->specifyExpressionType ($ exprToSpecify , $ exprTypeWithoutNull );
1234
+ $ nativeType = $ scope ->getNativeType ($ exprToSpecify );
1235
+ $ specifiedExpressions [] = new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType , $ nativeType );
1236
+ $ scope = $ scope ->specifyExpressionType (
1237
+ $ exprToSpecify ,
1238
+ $ exprTypeWithoutNull ,
1239
+ TypeCombinator::removeNull ($ nativeType )
1240
+ );
1236
1241
}
1237
1242
1238
1243
if ($ exprToSpecify instanceof PropertyFetch) {
@@ -1259,7 +1264,11 @@ private function ensureNonNullability(MutatingScope $scope, Expr $expr, bool $fi
1259
1264
private function revertNonNullability (MutatingScope $ scope , array $ specifiedExpressions ): MutatingScope
1260
1265
{
1261
1266
foreach ($ specifiedExpressions as $ specifiedExpressionResult ) {
1262
- $ scope = $ scope ->specifyExpressionType ($ specifiedExpressionResult ->getExpression (), $ specifiedExpressionResult ->getOriginalType ());
1267
+ $ scope = $ scope ->specifyExpressionType (
1268
+ $ specifiedExpressionResult ->getExpression (),
1269
+ $ specifiedExpressionResult ->getOriginalType (),
1270
+ $ specifiedExpressionResult ->getOriginalNativeType ()
1271
+ );
1263
1272
}
1264
1273
1265
1274
return $ scope ;
0 commit comments