File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ LogicalType
63
63
64
64
UnionType -> {
65
65
if (\count($children) === 2) {
66
+ if ($this->union === false) {
67
+ throw FeatureNotAllowedException::fromFeature('union types', $offset);
68
+ }
69
+
66
70
return new Node\Stmt\UnionTypeNode($children[0], $children[1]);
67
71
}
68
72
@@ -73,6 +77,10 @@ UnionType -> {
73
77
74
78
IntersectionType -> {
75
79
if (\count($children) === 2) {
80
+ if ($this->intersection === false) {
81
+ throw FeatureNotAllowedException::fromFeature('intersection types', $offset);
82
+ }
83
+
76
84
return new Node\Stmt\IntersectionTypeNode($children[0], $children[1]);
77
85
}
78
86
@@ -114,6 +122,10 @@ TypesList -> {
114
122
$statement = \array_shift($children);
115
123
116
124
for ($i = 0, $length = \count($children); $i < $length; ++$i) {
125
+ if ($this->list === false) {
126
+ throw FeatureNotAllowedException::fromFeature('square bracket list types', $offset);
127
+ }
128
+
117
129
$statement = new Node\Stmt\TypesListNode($statement);
118
130
$statement->offset = $children[$i]->getOffset();
119
131
}
Original file line number Diff line number Diff line change 1
1
2
2
TemplateArguments -> {
3
+ if ($this->generics === false) {
4
+ throw FeatureNotAllowedException::fromFeature('template arguments', $offset);
5
+ }
6
+
3
7
return new Node\Stmt\Template\ArgumentsListNode($children);
4
8
}
5
9
: ::T_ANGLE_BRACKET_OPEN::
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class FeatureNotAllowedException extends SemanticException
14
14
*/
15
15
public static function fromFeature (string $ name , int $ offset = 0 ): self
16
16
{
17
- $ message = \sprintf ('%s not allowed by parser configuration ' , $ name );
17
+ $ message = \sprintf ('%s not allowed ' , $ name );
18
18
19
19
return new static ($ offset , $ message );
20
20
}
Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ public function __construct(
73
73
public readonly bool $ shapes = true ,
74
74
public readonly bool $ callables = true ,
75
75
public readonly bool $ literals = true ,
76
+ public readonly bool $ generics = true ,
77
+ public readonly bool $ union = true ,
78
+ public readonly bool $ intersection = true ,
79
+ public readonly bool $ list = true ,
76
80
private readonly SourceFactoryInterface $ sources = new SourceFactory (),
77
81
) {
78
82
/** @psalm-var GrammarConfigArray $grammar */
You can’t perform that action at this time.
0 commit comments