1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add offset to atomic type

Ref #1832
This commit is contained in:
Matthew Brown 2019-06-23 00:19:41 -04:00
parent 31c8a2e4d7
commit ec104be6e2
5 changed files with 33 additions and 5 deletions

View File

@ -42,7 +42,15 @@ class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface
}
}
$new_candidate_type = implode('', $type_tokens);
$new_candidate_type = implode(
'',
array_map(
function ($f) {
return $f[0];
},
$type_tokens
)
);
if ($new_candidate_type !== $candidate_type) {
$bounds = $code_location->getSelectionBounds();

View File

@ -501,6 +501,7 @@ class ParseTree
$new_leaf = new ParseTree\Value(
$type_token[0] . '::' . $nexter_token[0],
$type_token[1],
$new_parent
);
@ -515,6 +516,7 @@ class ParseTree
$new_leaf = new ParseTree\Value(
$type_token[0],
$type_token[1],
$new_parent
);
break;

View File

@ -11,12 +11,18 @@ class Value extends \Psalm\Internal\Type\ParseTree
*/
public $value;
/**
* @var int
*/
public $offset;
/**
* @param string $value
* @param \Psalm\Internal\Type\ParseTree|null $parent
*/
public function __construct($value, \Psalm\Internal\Type\ParseTree $parent = null)
public function __construct(string $value, int $offset, \Psalm\Internal\Type\ParseTree $parent = null)
{
$this->offset = $offset;
$this->value = $value;
$this->parent = $parent;
}

View File

@ -127,7 +127,10 @@ abstract class Type
$only_token[0] = self::fixScalarTerms($only_token[0], $php_version);
return new Union([Atomic::create($only_token[0], $php_version, $template_type_map)]);
$atomic = Atomic::create($only_token[0], $php_version, $template_type_map);
$atomic->offset = 0;
return new Union([$atomic]);
}
$parse_tree = ParseTree::createFromTokens($type_tokens);
@ -649,9 +652,13 @@ abstract class Type
throw new TypeParseTreeException('Invalid type \'' . $parse_tree->value . '\'');
}
$atomic_type = self::fixScalarTerms($parse_tree->value, $php_version);
$atomic_type_string = self::fixScalarTerms($parse_tree->value, $php_version);
return Atomic::create($atomic_type, $php_version, $template_type_map);
$atomic_type = Atomic::create($atomic_type_string, $php_version, $template_type_map);
$atomic_type->offset = $parse_tree->offset;
return $atomic_type;
}
private static function getGenericParamClass(

View File

@ -67,6 +67,11 @@ abstract class Atomic
*/
public $from_docblock = false;
/**
* @var ?int
*/
public $offset;
/**
* @param string $value
* @param array{int,int}|null $php_version