transformer: fix a bug with string literal length (#14757)
parent
6d8a0ad15d
commit
e4e858b132
|
@ -1,2 +1,4 @@
|
||||||
5
|
5
|
||||||
7
|
7
|
||||||
|
6
|
||||||
|
6
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
a := 'Vlang'.len
|
a := 'Vlang'.len
|
||||||
b := r'Vlang\n'.len
|
b := r'Vlang\n'.len
|
||||||
|
c := 'Vlang\n'.len
|
||||||
|
d := 'Vlang$a'.len
|
||||||
println(a)
|
println(a)
|
||||||
println(b)
|
println(b)
|
||||||
|
println(c)
|
||||||
|
println(d)
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,9 +637,11 @@ pub fn (mut t Transformer) expr(mut node ast.Expr) ast.Expr {
|
||||||
ast.SelectorExpr {
|
ast.SelectorExpr {
|
||||||
node.expr = t.expr(mut node.expr)
|
node.expr = t.expr(mut node.expr)
|
||||||
if mut node.expr is ast.StringLiteral && node.field_name == 'len' {
|
if mut node.expr is ast.StringLiteral && node.field_name == 'len' {
|
||||||
return ast.IntegerLiteral{
|
if !node.expr.val.contains('\\') || node.expr.is_raw {
|
||||||
val: node.expr.val.len.str()
|
return ast.IntegerLiteral{
|
||||||
pos: node.pos
|
val: node.expr.val.len.str()
|
||||||
|
pos: node.pos
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue