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:
parent
7bcf7f13b1
commit
818e3be00c
@ -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();
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user