fix(selfhost/parser): skip newlines inside expressions

The selfhost parser did not skip tkNewLine tokens inside expression parsing,
causing multi-line expressions (e.g. if conditions spanning lines with ||)
to be truncated. When parserParseBinaryPrec hit a newline it treated it as
an invalid primary, returning a malformed literal and leaving p.pos at the
newline. parserParseBlock then failed to find '{' and its depth-counter
fallback consumed far too many tokens, causing subsequent function bodies
to be parsed into the wrong AST nodes.

Fix: add newline skipping in parserParsePrimary, parserParseUnary, and
parserParseBinaryPrec, matching the bootstrap parser's skipNewlines() calls
in parseAnd/parseOr.

Also complete the variant cap raise from 8->9 in src/sema.bux (was already
done in ast.bux, parser.bux, hir_lower.bux).
This commit is contained in:
2026-06-08 19:45:05 +03:00
parent b1deff7fd5
commit 2cb971a483
5 changed files with 74 additions and 31 deletions
+1
View File
@@ -265,6 +265,7 @@ struct Decl {
variant5: EnumVariant,
variant6: EnumVariant,
variant7: EnumVariant,
variant8: EnumVariant,
// Impl methods (up to 4)
methodCount: int,
// Use/import
+1
View File
@@ -1006,6 +1006,7 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule {
if vi == 5 { v = &decl.variant5; }
if vi == 6 { v = &decl.variant6; }
if vi == 7 { v = &decl.variant7; }
if vi == 8 { v = &decl.variant8; }
if v != null as *EnumVariant {
hm.enums[ei].variants[vi].name = v.name;
hm.enums[ei].variants[vi].fieldCount = v.fieldCount;
+11 -1
View File
@@ -236,6 +236,9 @@ func parserMakeExpr(kind: int, line: uint32, col: uint32) -> *Expr {
// ---------------------------------------------------------------------------
func parserParsePrimary(p: *Parser) -> *Expr {
while parserCheck(p, tkNewLine) {
discard parserAdvance(p);
}
let tok: LexToken = parserCurToken(p);
let line: uint32 = tok.line;
let col: uint32 = tok.column;
@@ -572,6 +575,9 @@ func parserPrecedence(op: int) -> int {
}
func parserParseUnary(p: *Parser) -> *Expr {
while parserCheck(p, tkNewLine) {
discard parserAdvance(p);
}
let tok: LexToken = parserCurToken(p);
let line: uint32 = tok.line;
let col: uint32 = tok.column;
@@ -592,6 +598,9 @@ func parserParseUnary(p: *Parser) -> *Expr {
func parserParseBinaryPrec(p: *Parser, minPrec: int) -> *Expr {
var left: *Expr = parserParseUnary(p);
while true {
while parserCheck(p, tkNewLine) {
discard parserAdvance(p);
}
let op: int = parserPeek(p, 0);
let prec: int = parserPrecedence(op);
if prec < minPrec { break; }
@@ -1851,7 +1860,7 @@ func parserParseEnumDecl(p: *Parser, isPublic: bool) -> *Decl {
discard parserExpect(p, tkLBrace, "expected '{'");
while !parserCheck(p, tkRBrace) && parserPeek(p, 0) != tkEndOfFile {
if d.variantCount >= 8 { break; }
if d.variantCount >= 9 { break; }
if parserCheck(p, tkNewLine) || parserCheck(p, tkSemicolon) { discard parserAdvance(p); continue; }
let vName: LexToken = parserExpect(p, tkIdent, "expected variant name");
@@ -1882,6 +1891,7 @@ func parserParseEnumDecl(p: *Parser, isPublic: bool) -> *Decl {
else if d.variantCount == 5 { d.variant5 = v; }
else if d.variantCount == 6 { d.variant6 = v; }
else if d.variantCount == 7 { d.variant7 = v; }
else if d.variantCount == 8 { d.variant8 = v; }
d.variantCount = d.variantCount + 1;
parserMatch(p, tkComma);
+2 -1
View File
@@ -490,7 +490,7 @@ func Sema_CollectGlobals(sema: *Sema) {
// Register enum variants as constants
var vi: int = 0;
while vi < decl.variantCount && vi < 8 {
while vi < decl.variantCount && vi < 9 {
var v: EnumVariant;
if vi == 0 { v = decl.variant0; }
else if vi == 1 { v = decl.variant1; }
@@ -500,6 +500,7 @@ func Sema_CollectGlobals(sema: *Sema) {
else if vi == 5 { v = decl.variant5; }
else if vi == 6 { v = decl.variant6; }
else if vi == 7 { v = decl.variant7; }
else if vi == 8 { v = decl.variant8; }
if v.name == null as String || String_Eq(v.name, "") {
vi = vi + 1;
continue;