Merge pull request #6861 from BradLewis/fix/parse-multiline-ternary

Correct divergence with expr levels causing failures with the odin parser
This commit is contained in:
gingerBill
2026-06-21 23:08:05 +01:00
committed by GitHub
2 changed files with 55 additions and 9 deletions

View File

@@ -94,3 +94,40 @@ test_parse_stb_image :: proc(t: ^testing.T) {
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
}
}
@test
test_parse_multiline_ternary :: proc(t: ^testing.T) {
context.allocator = context.temp_allocator
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
file := ast.File{
fullpath = "test.odin",
src = `
package main
my_func :: proc (cond: bool, a: string, b: string) -> string {
out := (
cond
? a
: b
)
return out
}
`,
}
p := parser.default_parser()
p.err = proc(pos: tokenizer.Pos, format: string, args: ..any) {
message := fmt.tprintf(format, ..args)
log.errorf("%s(%d:%d): %s", pos.file, pos.line, pos.column, message)
}
p.warn = proc(pos: tokenizer.Pos, format: string, args: ..any) {
message := fmt.tprintf(format, ..args)
log.warnf("%s(%d:%d): %s", pos.file, pos.line, pos.column, message)
}
ok := parser.parse_file(&p, &file)
testing.expect(t, ok, "bad parse")
testing.expect(t, file.syntax_error_count == 0, "should contain zero errors")
}