fmt: don't break indexing in string interpolation. (#10195)

pull/10199/head
Ryan Roden-Corrent 2021-05-25 00:45:32 -04:00 committed by GitHub
parent 7d210da9a5
commit 306c16f0fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -180,7 +180,7 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) {
} else if sub_expr.left is CallExpr {
sub_expr = sub_expr.left
continue
} else if sub_expr.left is CastExpr {
} else if sub_expr.left is CastExpr || sub_expr.left is IndexExpr {
needs_braces = true
}
break

View File

@ -7,9 +7,11 @@ fn main() {
b := 'xyz'
e := 'a: $a b: $b i: $i'
d := 'a: ${a:5s} b: ${b:-5s} i: ${i:20d}'
f := 'a byte string'.bytes()
println('a: $a $b xxx')
eprintln('e: $e')
_ = ' ${foo.method(bar).str()} '
println('(${some_struct.@type}, $some_struct.y)')
_ := 'CastExpr ${int(d.e).str()}'
println('${f[0..4].bytestr()}')
}