mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #116 - be more lenient with static vars
This commit is contained in:
parent
7fad81edac
commit
04363237c5
@ -473,10 +473,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource
|
||||
}
|
||||
|
||||
if ($context->check_variables) {
|
||||
$context->vars_in_scope['$' . $var->name] = $var->default && isset($var->default->inferredType)
|
||||
? $var->default->inferredType
|
||||
: Type::getMixed();
|
||||
|
||||
$context->vars_in_scope['$' . $var->name] = Type::getMixed();
|
||||
$context->vars_possibly_in_scope['$' . $var->name] = true;
|
||||
$this->registerVariable('$' . $var->name, new CodeLocation($this, $stmt));
|
||||
}
|
||||
|
@ -377,23 +377,6 @@ class ScopeTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStatic()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function a() : string {
|
||||
static $foo = "foo";
|
||||
|
||||
return $foo;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidGlobal
|
||||
@ -633,4 +616,45 @@ class ScopeTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage MixedInferredReturnType
|
||||
* @return void
|
||||
*/
|
||||
public function testStatic()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function a() : string {
|
||||
static $foo = "foo";
|
||||
|
||||
return $foo;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStaticNullRef()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
/** @return void */
|
||||
function foo() {
|
||||
static $bar = null;
|
||||
|
||||
if ($bar !== null) {
|
||||
// do something
|
||||
}
|
||||
|
||||
$bar = 5;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user