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

Fix issue with slashes after ? in type

This commit is contained in:
Matt Brown 2018-05-21 12:55:44 -04:00
parent aebbd473d9
commit a30d229040
3 changed files with 20 additions and 1 deletions

View File

@ -404,7 +404,7 @@ abstract class Type
public static function tokenize($string_type, $ignore_space = true)
{
// remove all unacceptable characters
$string_type = preg_replace('/\?(?=[a-zA-Z])/', 'null|', $string_type);
$string_type = preg_replace('/\?(?=[\\\\a-zA-Z])/', 'null|', $string_type);
$type_tokens = [''];
$was_char = false;

View File

@ -769,6 +769,17 @@ class AnnotationTest extends TestCase
'$e' => 'callable():string',
],
],
'slashAfter?' => [
'<?php
namespace ns;
/** @param ?\stdClass $s */
function foo($s) : void {
}
foo(null);
foo(new \stdClass);',
],
];
}

View File

@ -61,6 +61,14 @@ class TypeParseTest extends TestCase
$this->assertSame('null|string', (string) Type::parseString('?string'));
}
/**
* @return void
*/
public function testNullableFullyQualified()
{
$this->assertSame('null|stdClass', (string) Type::parseString('?\\stdClass'));
}
/**
* @return void
*/