Skip to content

Commit b065740

Browse files
committed
fix: allow type use annotations in catch params
1 parent ef003b2 commit b065740

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,10 @@ module.exports = grammar({
634634
$._variable_declarator_id,
635635
),
636636

637-
catch_type: $ => sep1($._unannotated_type, '|'),
637+
catch_type: $ => seq(
638+
$._unannotated_type, // first type's annotations will be parsed as modifiers
639+
repeat(seq('|', $._type)),
640+
),
638641

639642
finally_clause: $ => seq('finally', $.block),
640643

test/corpus/expressions.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,3 +1951,38 @@ void foo(int @Foo ... x) {
19511951
(variable_declarator
19521952
(identifier))))
19531953
(block)))
1954+
1955+
================================================================================
1956+
Annotations in a catch type
1957+
================================================================================
1958+
1959+
try {
1960+
} catch (@A1 @A2 final @A3 @A4 T1 | @A5 @A6 T2 e) {
1961+
}
1962+
1963+
---
1964+
1965+
(program
1966+
(try_statement
1967+
(block)
1968+
(catch_clause
1969+
(catch_formal_parameter
1970+
(modifiers
1971+
(marker_annotation
1972+
(identifier))
1973+
(marker_annotation
1974+
(identifier))
1975+
(marker_annotation
1976+
(identifier))
1977+
(marker_annotation
1978+
(identifier)))
1979+
(catch_type
1980+
(type_identifier)
1981+
(annotated_type
1982+
(marker_annotation
1983+
(identifier))
1984+
(marker_annotation
1985+
(identifier))
1986+
(type_identifier)))
1987+
(identifier))
1988+
(block))))

0 commit comments

Comments
 (0)