mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add support for ?A types in docblock
This commit is contained in:
parent
9220b958eb
commit
317eab8730
@ -11,7 +11,7 @@ use Psalm\Type;
|
||||
class CommentChecker
|
||||
{
|
||||
const TYPE_REGEX =
|
||||
'(\\\?[A-Za-z0-9_\<,\>\[\]\-\{\}:|\\\]+|\$[a-zA-Z_0-9_\<,\>\|\[\]-\{\}:]+)';
|
||||
'(\??\\\?[A-Za-z0-9_\<,\>\[\]\-\{\}:|\\\]+|\$[a-zA-Z_0-9_\<,\>\|\[\]-\{\}:]+)';
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
|
@ -55,6 +55,26 @@ class Php71Test extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('string|null', (string) $context->vars_in_scope['$a']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testNullableReturnTypeInDocblock()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
/** @return ?string */
|
||||
function a() {
|
||||
return rand(0, 10) ? "elePHPant" : null;
|
||||
}
|
||||
|
||||
$a = a();
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
$this->assertEquals('null|string', (string) $context->vars_in_scope['$a']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user