checker: fix const type with raw string literal (#12761)

pull/12769/head
yuyi 2021-12-09 04:28:55 +08:00 committed by GitHub
parent cd96f980cc
commit d88e67a5ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -8732,7 +8732,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp
return expr.val.i64()
}
ast.StringLiteral {
return expr.val
return util.smart_quote(expr.val, expr.is_raw)
}
ast.CharLiteral {
runes := expr.val.runes()

View File

@ -0,0 +1,29 @@
const ca = r'x\n'
const cb = 'x\n'
const cc = ca + cb
const cd = cc + cc
const ce = cd + cd
fn test_many_pluses_with_raw_string_literal() {
a := r'x\n'
assert a == ca
b := 'x\n'
assert b == cb
c := a + b
assert c == cc
d := c + c
assert d == cd
e := d + d
assert e == ce
println(e)
result := r'x\nx
x\nx
x\nx
x\nx
'
assert e == result
}