Skip to content

Fix resolving of __DIR__, __NAMESPACE__ in traits#2043

Merged
ondrejmirtes merged 5 commits intophpstan:1.9.xfrom
staabm:trait-magic
Jan 11, 2023
Merged

Fix resolving of __DIR__, __NAMESPACE__ in traits#2043
ondrejmirtes merged 5 commits intophpstan:1.9.xfrom
staabm:trait-magic

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Dec 3, 2022

closes phpstan/phpstan#3019

the test fails without the fix like

There were 2 failures:

1) PHPStan\Analyser\NodeScopeResolverTest::testFileAsserts with data set "/Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/data/bug-3019.php:11" ('type', '/Users/staabm/workspace/phpst...19.php', PHPStan\Type\Constant\ConstantStringType Object (...), PHPStan\Type\Constant\ConstantStringType Object (...), 11)
Expected type string, got type 'Bug3019\\Bar' in /Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/data/bug-3019.php on line 11.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'string'
+''Bug3019\\Bar''

/Users/staabm/workspace/phpstan-src/src/Testing/TypeInferenceTestCase.php:96
/Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/NodeScopeResolverTest.php:1150

2) PHPStan\Analyser\NodeScopeResolverTest::testFileAsserts with data set "/Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/data/bug-3019.php:12" ('type', '/Users/staabm/workspace/phpst...19.php', PHPStan\Type\Constant\ConstantStringType Object (...), PHPStan\Type\Constant\ConstantStringType Object (...), 12)
Expected type string, got type 'Bug3019' in /Users/staabm/workspace/phpstan-src/tests/PHPStan/Analyser/data/bug-3019.php on line 12.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'string'
+''Bug3019''

3) PHPStan\Rules\Comparison\UnreachableTernaryElseBranchRuleTest::testBug3019
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'
+'09: Else branch is unreachable because ternary operator condition is always true.
 '

@staabm staabm marked this pull request as ready for review December 3, 2022 15:32
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the trait-magic branch 5 times, most recently from bd007ad to cc8c0ca Compare December 11, 2022 08:31
@staabm staabm force-pushed the trait-magic branch 4 times, most recently from eda5b21 to fe1e5ab Compare December 17, 2022 14:27
@staabm staabm force-pushed the trait-magic branch 3 times, most recently from d724ad9 to dac2fd9 Compare December 25, 2022 17:54
@staabm staabm force-pushed the trait-magic branch 2 times, most recently from 0a4f077 to c3b1032 Compare January 8, 2023 19:52
@staabm staabm force-pushed the trait-magic branch 2 times, most recently from fcbf700 to 8032644 Compare January 9, 2023 09:05
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am wondering that we don't get a class-string here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My guess it's not checked because a duplicate trait with the same name exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Duplicate namespaces/duplicate classes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just use a single file used in both RuleTestCase and NodeScopeResolverTest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahh good catch.

when I have some time I will work on the rule to detect duplicate namespaces :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My guess it's not checked because a duplicate trait with the same name exists.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Jan 9, 2023

should this be re-targeted for 1.10.x or will we still have 1.9.x releases before 1.10 is out?

@ondrejmirtes
Copy link
Copy Markdown
Member

or will we still have 1.9.x releases before 1.10 is out

Yeah, sure, that's the point of these branches :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I verified this code still fails without the patch for both Test-cases

@ondrejmirtes ondrejmirtes merged commit acee0af into phpstan:1.9.x Jan 11, 2023
@ondrejmirtes
Copy link
Copy Markdown
Member

Nice, thank you!

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.

Condition using __CLASS__ magic constant in trait

3 participants