Skip to content

Commit 27a6fae

Browse files
committed
parser: fix an edge case where expression of a short variable declaration assignment placed on the next statement may cause segfault
1 parent ecd618b commit 27a6fae

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

std/jule/parser/scope.jule

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,20 @@ impl scopeParser {
10091009
info.setter = token
10101010
if i+1 >= len(tokens) {
10111011
info.r = nil
1012-
info.ok = token::IsPostfix(info.setter.ID)
1012+
// Expression is missing.
1013+
// If the setter token is a postfix operator, accept it.
1014+
if token::IsPostfix(info.setter.ID) {
1015+
info.ok = true
1016+
break
1017+
}
1018+
// The setter token is not a postfix operator.
1019+
// Probably the following statement is the expression.
1020+
// We must try to handle next statement as expression.
1021+
if self.isLastSt() {
1022+
self.pushErr(info.setter, "expected expression")
1023+
break
1024+
}
1025+
info.r = self.next().tokens
10131026
break
10141027
}
10151028
info.r = tokens[i+1:]

0 commit comments

Comments
 (0)