Skip to content
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

Internal error: The current context does not have a class for self in file #5951

Closed
knallcharge opened this issue Nov 8, 2021 · 3 comments
Closed

Comments

@knallcharge
Copy link

Bug report

phpstan will issue a warning for each controller after updating to 1.1.1 (from 1.0.1)
"[WARNING] Internal error: Internal error: The current context does not have a class for self in file (...)"
using Symfony 5.3 and PHP 8 route attributes with constants for "name"

Code snippet that reproduces the problem

https://phpstan.org/r/0c5ec089-20d8-45e8-b946-5a0a63f4b09d

Expected output

no error

here's the stack trace

Uncaught RuntimeException: The current context does not have a class for self in phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/NodeCompiler/CompilerContext.php:41
#0 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/NodeCompiler/CompileNodeToValue.php(147): PHPStan\BetterReflection\NodeCompiler\CompilerContext->getSelf()
#1 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/NodeCompiler/CompileNodeToValue.php(41): PHPStan\BetterReflection\NodeCompiler\CompileNodeToValue->compileClassConstFetch(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\BetterReflection\NodeCompiler\CompilerContext))
#2 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php(131): PHPStan\BetterReflection\NodeCompiler\CompileNodeToValue->PHPStan\BetterReflection\NodeCompiler\{closure}(Object(PhpParser\Node\Expr\ClassConstFetch))
#3 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php(96): PhpParser\ConstExprEvaluator->evaluate(Object(PhpParser\Node\Expr\ClassConstFetch))
#4 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/NodeCompiler/CompileNodeToValue.php(87): PhpParser\ConstExprEvaluator->evaluateDirectly(Object(PhpParser\Node\Expr\ClassConstFetch))
#5 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionFunctionAbstract.php(517): PHPStan\BetterReflection\NodeCompiler\CompileNodeToValue->__invoke(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\BetterReflection\NodeCompiler\CompilerContext))
#6 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionMethod.php(240): PHPStan\BetterReflection\Reflection\ReflectionFunctionAbstract->getAttributes()
#7 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionMethod.php(233): PHPStan\BetterReflection\Reflection\ReflectionMethod->hasTentativeReturnType()
#8 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/Adapter/ReflectionMethod.php(181): PHPStan\BetterReflection\Reflection\ReflectionMethod->getReturnType()
#9 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/NativeBuiltinMethodReflection.php(101): PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod->getReturnType()
#10 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpClassReflectionExtension.php(475): PHPStan\Reflection\Php\NativeBuiltinMethodReflection->getReturnType()
#11 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpClassReflectionExtension.php(285): PHPStan\Reflection\Php\PhpClassReflectionExtension->createMethod(Object(PHPStan\Reflection\ClassReflection), Object(PHPStan\Reflection\Php\NativeBuiltinMethodReflection), false)
#12 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(330): PHPStan\Reflection\Php\PhpClassReflectionExtension->getNativeMethod(Object(PHPStan\Reflection\ClassReflection), 'index')
#13 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpMethodFromParserNodeReflection.php(67): PHPStan\Reflection\ClassReflection->getNativeMethod('index')
#14 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/OverridingMethodRule.php(53): PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection->getPrototype()
#15 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(77): PHPStan\Rules\Methods\OverridingMethodRule->processNode(Object(PHPStan\Node\InClassMethodNode), Object(PHPStan\Analyser\MutatingScope))
#16 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(91): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PHPStan\Node\InClassMethodNode), Object(PHPStan\Analyser\MutatingScope))
#17 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(393): PHPStan\Node\ClassStatementsGatherer->__invoke(Object(PHPStan\Node\InClassMethodNode), Object(PHPStan\Analyser\MutatingScope))
#18 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(249): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer))
#19 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(498): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer))
#20 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(249): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#21 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(464): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#22 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(217): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#23 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(164): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#24 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(52): PHPStan\Analyser\FileAnalyser->analyseFile('C:\\xampp\\htdocs...', Array, Object(PHPStan\Rules\Registry), NULL)
#25 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(56): PHPStan\Analyser\Analyser->analyse(Array, Object(Closure), NULL, true, Array)
#26 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(146): PHPStan\Command\AnalyserRunner->runAnalyser(Array, Array, Object(Closure), NULL, true, true, 'C:\\xampp\\htdocs...', NULL, NULL, Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput))
#27 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(78): PHPStan\Command\AnalyseApplication->runAnalyser(Array, Array, true, 'C:\\xampp\\htdocs...', Object(PHPStan\Command\Symfony\SymfonyOutput), Object(PHPStan\Command\Symfony\SymfonyOutput), Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput))
#28 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(144): PHPStan\Command\AnalyseApplication->analyse(Array, false, Object(PHPStan\Command\Symfony\SymfonyOutput), Object(PHPStan\Command\Symfony\SymfonyOutput), false, true, 'C:\\xampp\\htdocs...', Array, Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput))
#29 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(228): PHPStan\Command\AnalyseCommand->execute(Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_9b5387833\Symfony\Component\Console\Output\ConsoleOutput))
#30 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_9b5387833\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_9b5387833\Symfony\Component\Console\Output\ConsoleOutput))
#31 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(237): _PHPStan_9b5387833\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\AnalyseCommand), Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_9b5387833\Symfony\Component\Console\Output\ConsoleOutput))
#32 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(138): _PHPStan_9b5387833\Symfony\Component\Console\Application->doRun(Object(_PHPStan_9b5387833\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_9b5387833\Symfony\Component\Console\Output\ConsoleOutput))#33 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(82): _PHPStan_9b5387833\Symfony\Component\Console\Application->run()
#34 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(83): _PHPStan_9b5387833\{closure}()
#35 (...)\vendor\phpstan\phpstan\phpstan(8): require('phar://C:/xampp...')
#36 {main}
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@b5e44f7

@knallcharge
Copy link
Author

Works like a charm in 1.1.2, thanks a lot!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants