mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
transformer: fix a bug with string literal length (#14757)
This commit is contained in:
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,9 +637,11 @@ 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' {
|
||||
return ast.IntegerLiteral{
|
||||
val: node.expr.val.len.str()
|
||||
pos: node.pos
|
||||
if !node.expr.val.contains('\\') || node.expr.is_raw {
|
||||
return ast.IntegerLiteral{
|
||||
val: node.expr.val.len.str()
|
||||
pos: node.pos
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user