Skip to content

Commit 7e88ede

Browse files
author
Kirill Nesmeyanov
committed
Fix parser psalm errors
1 parent 4d9c25d commit 7e88ede

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Exception/FeatureNotAllowedException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
final class FeatureNotAllowedException extends SemanticException
88
{
9+
/**
10+
* @param non-empty-string $name
11+
* @param int<0, max> $offset
12+
*/
913
public static function fromFeature(string $name, int $offset = 0): self
1014
{
1115
$message = \sprintf('%s not allowed by parser configuration', $name);

src/Parser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ private function createLexer(array $grammar): Lexer
120120
*/
121121
public function parse(#[Language('PHP')] mixed $source): ?TypeStatement
122122
{
123+
$this->lastProcessedTokenOffset = 0;
124+
123125
/** @psalm-suppress PossiblyInvalidArgument */
124126
$source = File::new($source);
125127

@@ -132,9 +134,12 @@ public function parse(#[Language('PHP')] mixed $source): ?TypeStatement
132134
foreach ($this->parser->parse($source) as $stmt) {
133135
if ($stmt instanceof TypeStatement) {
134136
$context = $this->parser->getLastExecutionContext();
135-
$token = $context->buffer->current();
136137

137-
$this->lastProcessedTokenOffset = $token->getOffset();
138+
if ($context !== null) {
139+
$token = $context->buffer->current();
140+
141+
$this->lastProcessedTokenOffset = $token->getOffset();
142+
}
138143

139144
return $stmt;
140145
}

0 commit comments

Comments
 (0)