@@ -61,7 +61,12 @@ public function parse(TokenIterator $tokens): Ast\Type\TypeNode
6161 return $ this ->enrichWithAttributes ($ tokens , $ type , $ startLine , $ startIndex );
6262 }
6363
64- private function enrichWithAttributes (TokenIterator $ tokens , Ast \Type \TypeNode $ type , int $ startLine , int $ startIndex ): Ast \Type \TypeNode
64+ /**
65+ * @template T of Ast\Node
66+ * @param T $type
67+ * @return T
68+ */
69+ private function enrichWithAttributes (TokenIterator $ tokens , Ast \Node $ type , int $ startLine , int $ startIndex ): Ast \Node
6570 {
6671 $ endLine = $ tokens ->currentTokenLine ();
6772 $ endIndex = $ tokens ->currentTokenIndex ();
@@ -139,7 +144,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
139144 }
140145
141146 if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_THIS_VARIABLE )) {
142- $ type = new Ast \Type \ThisTypeNode ();
147+ $ type = $ this -> enrichWithAttributes ( $ tokens , new Ast \Type \ThisTypeNode (), $ startLine , $ startIndex );
143148
144149 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
145150 $ type = $ this ->tryParseArrayOrOffsetAccess ($ tokens , $ type );
@@ -151,7 +156,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
151156 $ currentTokenValue = $ tokens ->currentTokenValue ();
152157 $ tokens ->pushSavePoint (); // because of ConstFetchNode
153158 if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_IDENTIFIER )) {
154- $ type = new Ast \Type \IdentifierTypeNode ($ currentTokenValue );
159+ $ type = $ this -> enrichWithAttributes ( $ tokens , new Ast \Type \IdentifierTypeNode ($ currentTokenValue), $ startLine , $ startIndex );
155160
156161 if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_DOUBLE_COLON )) {
157162 $ tokens ->dropSavePoint (); // because of ConstFetchNode
@@ -454,7 +459,10 @@ private function parseCallable(TokenIterator $tokens, Ast\Type\IdentifierTypeNod
454459
455460 $ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_PARENTHESES );
456461 $ tokens ->consumeTokenType (Lexer::TOKEN_COLON );
457- $ returnType = $ this ->parseCallableReturnType ($ tokens );
462+
463+ $ startLine = $ tokens ->currentTokenLine ();
464+ $ startIndex = $ tokens ->currentTokenIndex ();
465+ $ returnType = $ this ->enrichWithAttributes ($ tokens , $ this ->parseCallableReturnType ($ tokens ), $ startLine , $ startIndex );
458466
459467 return new Ast \Type \CallableTypeNode ($ identifier , $ parameters , $ returnType );
460468 }
@@ -463,6 +471,8 @@ private function parseCallable(TokenIterator $tokens, Ast\Type\IdentifierTypeNod
463471 /** @phpstan-impure */
464472 private function parseCallableParameter (TokenIterator $ tokens ): Ast \Type \CallableTypeParameterNode
465473 {
474+ $ startLine = $ tokens ->currentTokenLine ();
475+ $ startIndex = $ tokens ->currentTokenIndex ();
466476 $ type = $ this ->parse ($ tokens );
467477 $ isReference = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_REFERENCE );
468478 $ isVariadic = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_VARIADIC );
@@ -476,7 +486,12 @@ private function parseCallableParameter(TokenIterator $tokens): Ast\Type\Callabl
476486 }
477487
478488 $ isOptional = $ tokens ->tryConsumeTokenType (Lexer::TOKEN_EQUAL );
479- return new Ast \Type \CallableTypeParameterNode ($ type , $ isReference , $ isVariadic , $ parameterName , $ isOptional );
489+ return $ this ->enrichWithAttributes (
490+ $ tokens ,
491+ new Ast \Type \CallableTypeParameterNode ($ type , $ isReference , $ isVariadic , $ parameterName , $ isOptional ),
492+ $ startLine ,
493+ $ startIndex
494+ );
480495 }
481496
482497
0 commit comments