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
6363
6464UnionType -> {
6565 if (\count($children) === 2) {
66+ if ($this->union === false) {
67+ throw FeatureNotAllowedException::fromFeature('union types', $offset);
68+ }
69+
6670 return new Node\Stmt\UnionTypeNode($children[0], $children[1]);
6771 }
6872
@@ -73,6 +77,10 @@ UnionType -> {
7377
7478IntersectionType -> {
7579 if (\count($children) === 2) {
80+ if ($this->intersection === false) {
81+ throw FeatureNotAllowedException::fromFeature('intersection types', $offset);
82+ }
83+
7684 return new Node\Stmt\IntersectionTypeNode($children[0], $children[1]);
7785 }
7886
@@ -114,6 +122,10 @@ TypesList -> {
114122 $statement = \array_shift($children);
115123
116124 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+
117129 $statement = new Node\Stmt\TypesListNode($statement);
118130 $statement->offset = $children[$i]->getOffset();
119131 }
Original file line number Diff line number Diff line change 11
22TemplateArguments -> {
3+ if ($this->generics === false) {
4+ throw FeatureNotAllowedException::fromFeature('template arguments', $offset);
5+ }
6+
37 return new Node\Stmt\Template\ArgumentsListNode($children);
48}
59 : ::T_ANGLE_BRACKET_OPEN::
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class FeatureNotAllowedException extends SemanticException
1414 */
1515 public static function fromFeature (string $ name , int $ offset = 0 ): self
1616 {
17- $ message = \sprintf ('%s not allowed by parser configuration ' , $ name );
17+ $ message = \sprintf ('%s not allowed ' , $ name );
1818
1919 return new static ($ offset , $ message );
2020 }
Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ public function __construct(
7373 public readonly bool $ shapes = true ,
7474 public readonly bool $ callables = true ,
7575 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 ,
7680 private readonly SourceFactoryInterface $ sources = new SourceFactory (),
7781 ) {
7882 /** @psalm-var GrammarConfigArray $grammar */
You can’t perform that action at this time.
0 commit comments