Fix crash due to parse error in module header (#1112)

This commit is contained in:
Jen Basch
2025-07-01 01:05:16 -07:00
committed by GitHub
parent f1388ffb2f
commit dbf57280ba
4 changed files with 10 additions and 1 deletions

View File

@@ -0,0 +1 @@
module "DoNotQuote"

View File

@@ -0,0 +1,6 @@
Pkl Error
Unexpected token `"`. Expected `identifier`.
x | module "DoNotQuote"
^
at invalidModule1 (file:///$snippetsDir/input/modules/invalidModule1.pkl)

View File

@@ -33,7 +33,8 @@ public final class Module extends AbstractNode {
public @Nullable ModuleDecl getDecl() {
assert children != null;
return (ModuleDecl) children.get(0);
// children can be empty when there was a parse error
return children.isEmpty() ? null : (ModuleDecl) children.get(0);
}
public List<ImportClause> getImports() {

View File

@@ -91,6 +91,7 @@ class ParserComparisonTest : ParserComparisonTestInterface {
"errors/underscore.pkl",
"notAUnionDefault.pkl",
"multipleDefaults.pkl",
"modules/invalidModule1.pkl",
)
private val regexExceptions =