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