Skip to content

implement FunctionReflection/ExtendedMethodReflection returnsByReference() #1899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 26, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 22, 2022

@staabm staabm force-pushed the returns-by-reference branch from 88e6eb6 to 9407908 Compare October 22, 2022 15:13
@staabm staabm marked this pull request as ready for review October 22, 2022 15:14
@@ -2563,6 +2563,7 @@ public function enterClassMethod(
$selfOutType,
$phpDocComment,
array_map(static fn (Type $type): Type => TemplateTypeHelper::toArgument($type), $parameterOutTypes),
null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since return-by-reference cannot be annotated by phpdocs only, I just ignore phpdocs regarding return-by-reference

@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the returns-by-reference branch 4 times, most recently from 7055b05 to 0801d7c Compare October 23, 2022 07:07
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you get back to this one, first thing to change is that returnsByReference returns TrinaryLogic. This is necessary for unions and intersections.

@staabm staabm force-pushed the returns-by-reference branch from 0801d7c to b03ee94 Compare October 26, 2022 08:41
@staabm staabm marked this pull request as draft October 26, 2022 08:42
@staabm
Copy link
Contributor Author

staabm commented Oct 26, 2022

When you get back to this one, first thing to change is that returnsByReference returns TrinaryLogic

done

@staabm staabm marked this pull request as ready for review October 26, 2022 09:19
@staabm staabm force-pushed the returns-by-reference branch from c924605 to c544d7f Compare October 26, 2022 09:20
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the returns-by-reference branch from c544d7f to 5cce436 Compare October 26, 2022 09:47
@staabm
Copy link
Contributor Author

staabm commented Oct 26, 2022

I tried adding tests for the case of unknown-functions, classes, and/or methods:

There were 5 errors:

1) PHPStan\Reflection\FunctionReflectionTest::testFunctionReturnsByReference with data set #1 ('\someUnknownFunction', PHPStan\TrinaryLogic Object (...))
PHPStan\Broker\FunctionNotFoundException: Function \someUnknownFunction not found while trying to analyse it - discovering symbols is probably not configured properly.

C:\dvl\Workspace\phpstan-src-staabm\src\Reflection\BetterReflection\BetterReflectionProvider.php:238
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Reflection\FunctionReflectionTest.php:151

2) PHPStan\Reflection\FunctionReflectionTest::testMethodReturnsByReference with data set #0 ('ReturnsByReference\SomeUnknownClass', 'foo', PHPStan\TrinaryLogic Object (...))
PHPStan\Broker\ClassNotFoundException: Class ReturnsByReference\SomeUnknownClass was not found while trying to analyse it - discovering symbols is probably not configured properly.

C:\dvl\Workspace\phpstan-src-staabm\src\Reflection\BetterReflection\BetterReflectionProvider.php:121
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Reflection\FunctionReflectionTest.php:186

3) PHPStan\Reflection\FunctionReflectionTest::testMethodReturnsByReference with data set #3 ('ReturnsByReference\X', 'someUnknownFunction', PHPStan\TrinaryLogic Object (...))
PHPStan\Reflection\MissingMethodFromReflectionException: Method someUnknownFunction() was not found in reflection of class ReturnsByReference\X.

C:\dvl\Workspace\phpstan-src-staabm\src\Reflection\ClassReflection.php:428
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Reflection\FunctionReflectionTest.php:193

4) PHPStan\Reflection\FunctionReflectionTest::testMethodReturnsByReference with data set #7 ('ReturnsByReference\SubX', 'someUnknownFunction', PHPStan\TrinaryLogic Object (...))
PHPStan\Reflection\MissingMethodFromReflectionException: Method someUnknownFunction() was not found in reflection of class ReturnsByReference\SubX.

C:\dvl\Workspace\phpstan-src-staabm\src\Reflection\ClassReflection.php:428
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Reflection\FunctionReflectionTest.php:193

5) PHPStan\Reflection\FunctionReflectionTest::testMethodReturnsByReference with data set #10 ('ReturnsByReference\TraitX', 'someUnknownFunction', PHPStan\TrinaryLogic Object (...))
PHPStan\Reflection\MissingMethodFromReflectionException: Method someUnknownFunction() was not found in reflection of class ReturnsByReference\TraitX.

C:\dvl\Workspace\phpstan-src-staabm\src\Reflection\ClassReflection.php:428
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Reflection\FunctionReflectionTest.php:193

these run into a exception right now... should this exception be catched and TrinaryLogic::createMaybe() be returned instead?

staabm and others added 4 commits October 26, 2022 13:30

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
…nce()

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@staabm staabm force-pushed the returns-by-reference branch from 5cce436 to 17f268d Compare October 26, 2022 11:30

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@clxmstaab clxmstaab force-pushed the returns-by-reference branch from 3c584e2 to 1c57728 Compare October 26, 2022 12:38

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@clxmstaab clxmstaab force-pushed the returns-by-reference branch from 1c57728 to 509b5b8 Compare October 26, 2022 12:40
@ondrejmirtes ondrejmirtes merged commit 97a729d into phpstan:1.9.x Oct 26, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the returns-by-reference branch October 26, 2022 13:06
@staabm
Copy link
Contributor Author

staabm commented Oct 26, 2022

thanks for the in-detail review @ondrejmirtes. much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add FunctionReflection/MethodReflection::returnsReference
3 participants