1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix issue with constants defined inside interfaces

This commit is contained in:
Matthew Brown 2017-01-16 00:13:08 -05:00
parent c78ce31e36
commit d46282e13f
2 changed files with 51 additions and 1 deletions

View File

@ -221,7 +221,8 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$interface_name,
$this->getFileChecker(),
new CodeLocation($this, $this->class, true),
$this->getSuppressedIssues()
$this->getSuppressedIssues(),
true
) === false) {
return false;
}
@ -233,11 +234,21 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
)
);
$interface_storage = self::$storage[strtolower($interface_name)];
// copy over any constants
$storage->public_class_constants = array_merge(
$storage->public_class_constants,
$interface_storage->public_class_constants
);
FileChecker::addFileInheritanceToClass($long_file_name, $interface_name);
}
$extra_interfaces = array_unique($extra_interfaces);
//var_dump(self::$storage);
foreach ($extra_interfaces as $extra_interface_name) {
FileChecker::addFileInheritanceToClass($long_file_name, $extra_interface_name);

View File

@ -473,4 +473,43 @@ class InterfaceTest extends PHPUnit_Framework_TestCase
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testInterfaceConstants()
{
$stmts = self::$parser->parse('<?php
interface I1 {
const A = 5;
const B = "two";
const C = 3.0;
}
interface I2 extends I1 {
const D = 5;
const E = "two";
}
class A implements I2 {
/** @var int */
public $foo = I1::A;
/** @var string */
public $bar = self::B;
/** @var float */
public $bar2 = I2::C;
/** @var int */
public $foo2 = I2::D;
/** @var string */
public $bar3 = self::E;
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
}