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

Fix #46 - fix type assignment of anonymous classes

This commit is contained in:
Matt Brown 2017-01-13 10:44:04 -05:00
parent e300550209
commit d2c9c423c5
2 changed files with 22 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class ClassChecker extends ClassLikeChecker
if ($fq_class_name === null) {
$fq_class_name = 'PsalmAnonymousClass' . (self::$anonymous_class_count++);
$class->name = $fq_class_name;
}
parent::__construct($class, $source, $fq_class_name);

View File

@ -150,6 +150,27 @@ class Php70Test extends PHPUnit_Framework_TestCase
$file_checker->visitAndAnalyzeMethods($context);
}
public function testAnonymousClassFunctionReturnType()
{
$stmts = self::$parser->parse('<?php
$class = new class {
public function f() : int {
return 42;
}
};
function g(int $i) : int {
return $i;
}
$x = g($class->f());
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context('somefile.php');
$file_checker->visitAndAnalyzeMethods($context);
}
public function testGeneratorWithReturn()
{
$stmts = self::$parser->parse('<?php