parser: fix wrong string parsing (fix #24297) (#24298)

This commit is contained in:
Felipe Pena 2025-04-24 07:53:31 -03:00 committed by GitHub
parent 59909cde89
commit 72f45e4434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -2762,7 +2762,8 @@ fn (mut p Parser) name_expr() ast.Expr {
}
}
// Raw string (`s := r'hello \n ')
if p.peek_tok.kind == .string && !p.inside_str_interp && p.peek_token(2).kind != .colon {
if p.peek_tok.kind == .string && p.tok.line_nr == p.peek_tok.line_nr && !p.inside_str_interp
&& p.peek_token(2).kind != .colon {
if p.tok.kind == .name && p.tok.lit in ['r', 'c', 'js'] {
return p.string_expr()
} else {

View File

@ -0,0 +1,28 @@
module main
fn if_expt(this int) (string, int) {
inc := 1
mut count := 0
thing := if this in [0, 1, 2] {
count += 1
'0..2'
} else if this in [3, 4, 5] {
count += inc
'3..5'
} else {
'not 0..5'
}
return thing, count
}
fn test_main() {
a, b := if_expt(1)
assert a == '0..2'
assert b == 1
c, d := if_expt(4)
assert c == '3..5'
assert d == 1
e, f := if_expt(7)
assert e == 'not 0..5'
assert f == 0
}