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:
parent
e300550209
commit
d2c9c423c5
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user