Skip to content

Commit ba281e8

Browse files
authored
Fix empty parenthesized type unexpected error (#1323)
1 parent bc5d675 commit ba281e8

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: Int|()|String = "foo"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
–– Pkl Error ––
2+
Unexpected token `)`. Expected a type.
3+
4+
x | foo: Int|()|String = "foo"
5+
^
6+
at emptyParenthesizedTypeAnnotation (file:///$snippetsDir/input/errors/emptyParenthesizedTypeAnnotation.pkl)

pkl-parser/src/main/java/org/pkl/parser/Parser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,9 @@ private Type parseTypeAtom(@Nullable String expectation) {
13931393
children.add(ret);
13941394
typ = new Type.FunctionType(children, tk.span.endWith(ret.span()));
13951395
} else {
1396+
if (children.isEmpty()) {
1397+
throw new ParserError(ErrorMessages.create("unexpectedTokenForType", ")"), end);
1398+
}
13961399
typ = new ParenthesizedType((Type) children.get(0), tk.span.endWith(end));
13971400
}
13981401
}

pkl-parser/src/test/kotlin/org/pkl/parser/ParserComparisonTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class ParserComparisonTest {
105105
"errors/moduleWithHighMinPklVersionAndParseErrors.pkl",
106106
"errors/underscore.pkl",
107107
"errors/shebang.pkl",
108+
"errors/emptyParenthesizedTypeAnnotation.pkl",
108109
"notAUnionDefault.pkl",
109110
"multipleDefaults.pkl",
110111
"modules/invalidModule1.pkl",

0 commit comments

Comments
 (0)