@@ -1442,6 +1442,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
14421442 if (array_key_exists ($ cacheKey , $ cachedTypes )) {
14431443 $ cachedClosureData = $ cachedTypes [$ cacheKey ];
14441444
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+
14451455 return new ClosureType (
14461456 $ parameters ,
14471457 $ cachedClosureData ['returnType ' ],
@@ -1454,6 +1464,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
14541464 invalidateExpressions: $ cachedClosureData ['invalidateExpressions ' ],
14551465 usedVariables: $ cachedClosureData ['usedVariables ' ],
14561466 acceptsNamedArguments: TrinaryLogic::createYes (),
1467+ mustUseReturnValue: $ mustUseReturnValue ,
14571468 );
14581469 }
14591470 if (self ::$ resolveClosureTypeDepth >= 2 ) {
@@ -1656,6 +1667,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
16561667 ];
16571668 $ node ->setAttribute ('phpstanCachedTypes ' , $ cachedTypes );
16581669
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+
16591680 return new ClosureType (
16601681 $ parameters ,
16611682 $ returnType ,
@@ -1668,6 +1689,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
16681689 invalidateExpressions: $ invalidateExpressions ,
16691690 usedVariables: $ usedVariables ,
16701691 acceptsNamedArguments: TrinaryLogic::createYes (),
1692+ mustUseReturnValue: $ mustUseReturnValue ,
16711693 );
16721694 } elseif ($ node instanceof New_) {
16731695 if ($ node ->class instanceof Name) {
@@ -2716,10 +2738,12 @@ private function createFirstClassCallable(
27162738 $ throwPoints = [];
27172739 $ impurePoints = [];
27182740 $ acceptsNamedArguments = TrinaryLogic::createYes ();
2741+ $ mustUseReturnValue = TrinaryLogic::createMaybe ();
27192742 if ($ variant instanceof CallableParametersAcceptor) {
27202743 $ throwPoints = $ variant ->getThrowPoints ();
27212744 $ impurePoints = $ variant ->getImpurePoints ();
27222745 $ acceptsNamedArguments = $ variant ->acceptsNamedArguments ();
2746+ $ mustUseReturnValue = $ variant ->mustUseReturnValue ();
27232747 } elseif ($ function !== null ) {
27242748 $ returnTypeForThrow = $ variant ->getReturnType ();
27252749 $ throwType = $ function ->getThrowType ();
@@ -2745,6 +2769,7 @@ private function createFirstClassCallable(
27452769 }
27462770
27472771 $ acceptsNamedArguments = $ function ->acceptsNamedArguments ();
2772+ $ mustUseReturnValue = $ function ->mustUseReturnValue ();
27482773 }
27492774
27502775 $ parameters = $ variant ->getParameters ();
@@ -2759,6 +2784,7 @@ private function createFirstClassCallable(
27592784 $ throwPoints ,
27602785 $ impurePoints ,
27612786 acceptsNamedArguments: $ acceptsNamedArguments ,
2787+ mustUseReturnValue: $ mustUseReturnValue ,
27622788 );
27632789 }
27642790
0 commit comments