1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix undefined global constant in closure

This commit is contained in:
Vladimir Komissarov 2017-04-14 17:03:09 +07:00
parent 7bcf7f13b1
commit 818e3be00c
2 changed files with 20 additions and 1 deletions

View File

@ -271,7 +271,7 @@ class ExpressionChecker
$use_context->vars_possibly_in_scope['$' . $use->var] = true;
}
$closure_checker->analyze($use_context);
$closure_checker->analyze($use_context, $context);
if (!isset($stmt->inferredType)) {
$stmt->inferredType = Type::getClosure();

View File

@ -56,6 +56,25 @@ class ConstantTest extends PHPUnit_Framework_TestCase
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testConstantInClosure()
{
$stmts = self::$parser->parse('<?php
const TEST = 2;
$useTest = function() : int {
return TEST;
};
$useTest();
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/