Skip to content

Commit 145842c

Browse files
committed
Improve error message when parsing truncated let expressions
1 parent 035ef0a commit 145842c

5 files changed

Lines changed: 12 additions & 2 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo {
2+
bar = let (qux = 1)
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
–– Pkl Error ––
2+
Unexpected token `}`.
3+
4+
x | }
5+
^
6+
at letExpressionError3 (file:///$snippetsDir/input/errors/letExpressionError3.pkl)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ private Node parseExprAtom(@Nullable String expectation) {
888888
expect(Token.RPAREN, paramDef, "unexpectedToken", ")");
889889
children.add(new Node(NodeType.LET_PARAMETER_DEFINITION, paramDef));
890890
ff(children);
891-
children.add(parseExpr(expectation));
891+
children.add(parseExpr());
892892
yield new Node(NodeType.LET_EXPR, children);
893893
}
894894
case TRUE, FALSE -> new Node(NodeType.BOOL_LITERAL_EXPR, next().span);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ yield switch (lookahead) {
10091009
expect(Token.ASSIGN, "unexpectedToken", "=");
10101010
var bindExpr = parseExpr(")");
10111011
expect(Token.RPAREN, "unexpectedToken", ")");
1012-
var exp = parseExpr(expectation);
1012+
var exp = parseExpr();
10131013
yield new LetExpr(param, bindExpr, exp, start.endWith(exp.span()));
10141014
}
10151015
case TRUE -> new BoolLiteralExpr(true, next().span);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ParserComparisonTest {
9999
"errors/invalidCharacterEscape.pkl",
100100
"errors/invalidCharacterEscape2.pkl",
101101
"errors/invalidUnicodeEscape.pkl",
102+
"errors/letExpressionError3.pkl",
102103
"errors/unterminatedUnicodeEscape.pkl",
103104
"errors/keywordNotAllowedHere1.pkl",
104105
"errors/keywordNotAllowedHere2.pkl",

0 commit comments

Comments
 (0)