Skip to content
Permalink
Browse files

Add offset to atomic type

Ref #1832
  • Loading branch information...
muglug committed Jun 23, 2019
1 parent 31c8a2e commit ec104be6e2651598d0adb44e593c1c283b381a57
@@ -42,7 +42,15 @@ public static function afterClassLikeExistenceCheck(
}
}
$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();
@@ -501,6 +501,7 @@ public static function createFromTokens(array $type_tokens)
$new_leaf = new ParseTree\Value(
$type_token[0] . '::' . $nexter_token[0],
$type_token[1],
$new_parent
);
@@ -515,6 +516,7 @@ public static function createFromTokens(array $type_tokens)
$new_leaf = new ParseTree\Value(
$type_token[0],
$type_token[1],
$new_parent
);
break;
@@ -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;
}
@@ -127,7 +127,10 @@ public static function parseTokens(
$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 @@ function (ParseTree $child_tree) use ($template_type_map) {
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);
$atomic_type = Atomic::create($atomic_type_string, $php_version, $template_type_map);
$atomic_type->offset = $parse_tree->offset;
return Atomic::create($atomic_type, $php_version, $template_type_map);
return $atomic_type;
}
private static function getGenericParamClass(
@@ -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

0 comments on commit ec104be

Please sign in to comment.
You can’t perform that action at this time.