@@ -1442,6 +1442,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1442
1442
if (array_key_exists ($ cacheKey , $ cachedTypes )) {
1443
1443
$ cachedClosureData = $ cachedTypes [$ cacheKey ];
1444
1444
1445
+ $ mustUseReturnValue = TrinaryLogic::createNo ();
1446
+ foreach ($ node ->attrGroups as $ attrGroup ) {
1447
+ foreach ($ attrGroup ->attrs as $ attr ) {
1448
+ if ($ attr ->name ->toLowerString () === 'nodiscard ' ) {
1449
+ $ mustUseReturnValue = TrinaryLogic::createYes ();
1450
+ break ;
1451
+ }
1452
+ }
1453
+ }
1454
+
1445
1455
return new ClosureType (
1446
1456
$ parameters ,
1447
1457
$ cachedClosureData ['returnType ' ],
@@ -1454,6 +1464,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1454
1464
invalidateExpressions: $ cachedClosureData ['invalidateExpressions ' ],
1455
1465
usedVariables: $ cachedClosureData ['usedVariables ' ],
1456
1466
acceptsNamedArguments: TrinaryLogic::createYes (),
1467
+ mustUseReturnValue: $ mustUseReturnValue ,
1457
1468
);
1458
1469
}
1459
1470
if (self ::$ resolveClosureTypeDepth >= 2 ) {
@@ -1656,6 +1667,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1656
1667
];
1657
1668
$ node ->setAttribute ('phpstanCachedTypes ' , $ cachedTypes );
1658
1669
1670
+ $ mustUseReturnValue = TrinaryLogic::createNo ();
1671
+ foreach ($ node ->attrGroups as $ attrGroup ) {
1672
+ foreach ($ attrGroup ->attrs as $ attr ) {
1673
+ if ($ attr ->name ->toLowerString () === 'nodiscard ' ) {
1674
+ $ mustUseReturnValue = TrinaryLogic::createYes ();
1675
+ break ;
1676
+ }
1677
+ }
1678
+ }
1679
+
1659
1680
return new ClosureType (
1660
1681
$ parameters ,
1661
1682
$ returnType ,
@@ -1668,6 +1689,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1668
1689
invalidateExpressions: $ invalidateExpressions ,
1669
1690
usedVariables: $ usedVariables ,
1670
1691
acceptsNamedArguments: TrinaryLogic::createYes (),
1692
+ mustUseReturnValue: $ mustUseReturnValue ,
1671
1693
);
1672
1694
} elseif ($ node instanceof New_) {
1673
1695
if ($ node ->class instanceof Name) {
@@ -2716,10 +2738,12 @@ private function createFirstClassCallable(
2716
2738
$ throwPoints = [];
2717
2739
$ impurePoints = [];
2718
2740
$ acceptsNamedArguments = TrinaryLogic::createYes ();
2741
+ $ mustUseReturnValue = TrinaryLogic::createMaybe ();
2719
2742
if ($ variant instanceof CallableParametersAcceptor) {
2720
2743
$ throwPoints = $ variant ->getThrowPoints ();
2721
2744
$ impurePoints = $ variant ->getImpurePoints ();
2722
2745
$ acceptsNamedArguments = $ variant ->acceptsNamedArguments ();
2746
+ $ mustUseReturnValue = $ variant ->mustUseReturnValue ();
2723
2747
} elseif ($ function !== null ) {
2724
2748
$ returnTypeForThrow = $ variant ->getReturnType ();
2725
2749
$ throwType = $ function ->getThrowType ();
@@ -2745,6 +2769,7 @@ private function createFirstClassCallable(
2745
2769
}
2746
2770
2747
2771
$ acceptsNamedArguments = $ function ->acceptsNamedArguments ();
2772
+ $ mustUseReturnValue = $ function ->mustUseReturnValue ();
2748
2773
}
2749
2774
2750
2775
$ parameters = $ variant ->getParameters ();
@@ -2759,6 +2784,7 @@ private function createFirstClassCallable(
2759
2784
$ throwPoints ,
2760
2785
$ impurePoints ,
2761
2786
acceptsNamedArguments: $ acceptsNamedArguments ,
2787
+ mustUseReturnValue: $ mustUseReturnValue ,
2762
2788
);
2763
2789
}
2764
2790
0 commit comments