@@ -522,51 +522,135 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
522522		$ startIndex$ tokenscurrentTokenIndex ();
523523		if  ($ tokensisCurrentTokenType (Lexer::TOKEN_NULLABLE )) {
524524			$ type$ this parseNullable ($ tokens
525+ 			if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
526+ 				$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
527+ 					$ tokens
528+ 					$ type
529+ 					$ startLine
530+ 					$ startIndex
531+ 				));
532+ 			}
533+ 
534+ 			return  $ type
525535
526536		} elseif  ($ tokenstryConsumeTokenType (Lexer::TOKEN_OPEN_PARENTHESES )) {
527537			$ type$ this parse ($ tokens
528538			$ tokensconsumeTokenType (Lexer::TOKEN_CLOSE_PARENTHESES );
539+ 			if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
540+ 				$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ type
541+ 			}
542+ 
543+ 			return  $ type
529544		} elseif  ($ tokenstryConsumeTokenType (Lexer::TOKEN_THIS_VARIABLE )) {
530545			$ typenew  Ast \Type \ThisTypeNode ();
546+ 			if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
547+ 				$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
548+ 					$ tokens
549+ 					$ type
550+ 					$ startLine
551+ 					$ startIndex
552+ 				));
553+ 			}
554+ 
555+ 			return  $ type
531556		} else  {
532- 			$ typenew  Ast \Type \IdentifierTypeNode ($ tokenscurrentTokenValue ());
533- 			$ tokensconsumeTokenType (Lexer::TOKEN_IDENTIFIER );
557+ 			$ currentTokenValue$ tokenscurrentTokenValue ();
558+ 			$ tokenspushSavePoint (); // because of ConstFetchNode 
559+ 			if  ($ tokenstryConsumeTokenType (Lexer::TOKEN_IDENTIFIER )) {
560+ 				$ typenew  Ast \Type \IdentifierTypeNode ($ currentTokenValue
561+ 
562+ 				if  (!$ tokensisCurrentTokenType (Lexer::TOKEN_DOUBLE_COLON )) {
563+ 					if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_ANGLE_BRACKET )) {
564+ 						$ type$ this parseGeneric (
565+ 							$ tokens
566+ 							$ this enrichWithAttributes (
567+ 								$ tokens
568+ 								$ type
569+ 								$ startLine
570+ 								$ startIndex
571+ 							)
572+ 						);
573+ 						if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
574+ 							$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
575+ 								$ tokens
576+ 								$ type
577+ 								$ startLine
578+ 								$ startIndex
579+ 							));
580+ 						}
581+ 
582+ 					} elseif  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
583+ 						$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
584+ 							$ tokens
585+ 							$ type
586+ 							$ startLine
587+ 							$ startIndex
588+ 						));
589+ 
590+ 					} elseif  (in_array ($ typename , ['array ' , 'list ' , 'object ' ], true ) && $ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_CURLY_BRACKET ) && !$ tokensisPrecededByHorizontalWhitespace ()) {
591+ 						if  ($ typename  === 'object ' ) {
592+ 							$ type$ this parseObjectShape ($ tokens
593+ 						} else  {
594+ 							$ type$ this parseArrayShape ($ tokens$ this enrichWithAttributes (
595+ 								$ tokens
596+ 								$ type
597+ 								$ startLine
598+ 								$ startIndex
599+ 							), $ typename );
600+ 						}
601+ 
602+ 						if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
603+ 							$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
604+ 								$ tokens
605+ 								$ type
606+ 								$ startLine
607+ 								$ startIndex
608+ 							));
609+ 						}
610+ 					}
534611
535- 			if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_ANGLE_BRACKET )) {
536- 				$ type$ this parseGeneric (
537- 					$ tokens
538- 					$ this enrichWithAttributes (
539- 						$ tokens
540- 						$ type
541- 						$ startLine
542- 						$ startIndex
543- 					)
544- 				);
545- 
546- 			} elseif  (in_array ($ typename , ['array ' , 'list ' , 'object ' ], true ) && $ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_CURLY_BRACKET ) && !$ tokensisPrecededByHorizontalWhitespace ()) {
547- 				if  ($ typename  === 'object ' ) {
548- 					$ type$ this parseObjectShape ($ tokens
612+ 					return  $ type
549613				} else  {
550- 					$ type$ this parseArrayShape ($ tokens$ this enrichWithAttributes (
551- 						$ tokens
552- 						$ type
553- 						$ startLine
554- 						$ startIndex
555- 					), $ typename );
614+ 					$ tokensrollback (); // because of ConstFetchNode 
556615				}
616+ 			} else  {
617+ 				$ tokensdropSavePoint (); // because of ConstFetchNode 
557618			}
558619		}
559620
560- 		if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
561- 			$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
562- 				$ tokens
563- 				$ type
564- 				$ startLine
565- 				$ startIndex
566- 			));
621+ 		$ exceptionnew  ParserException (
622+ 			$ tokenscurrentTokenValue (),
623+ 			$ tokenscurrentTokenType (),
624+ 			$ tokenscurrentTokenOffset (),
625+ 			Lexer::TOKEN_IDENTIFIER ,
626+ 			null ,
627+ 			$ tokenscurrentTokenLine ()
628+ 		);
629+ 
630+ 		if  ($ this constExprParser  === null ) {
631+ 			throw  $ exception
567632		}
568633
569- 		return  $ type
634+ 		try  {
635+ 			$ constExpr$ this constExprParser ->parse ($ tokenstrue );
636+ 			if  ($ constExprinstanceof  Ast \ConstExpr \ConstExprArrayNode) {
637+ 				throw  $ exception
638+ 			}
639+ 
640+ 			$ typenew  Ast \Type \ConstTypeNode ($ constExpr
641+ 			if  ($ tokensisCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
642+ 				$ type$ this tryParseArrayOrOffsetAccess ($ tokens$ this enrichWithAttributes (
643+ 					$ tokens
644+ 					$ type
645+ 					$ startLine
646+ 					$ startIndex
647+ 				));
648+ 			}
649+ 
650+ 			return  $ type
651+ 		} catch  (LogicException $ e
652+ 			throw  $ exception
653+ 		}
570654	}
571655
572656
0 commit comments