1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix formating cascade generic types call_expr (#10107)

This commit is contained in:
yuyi 2021-05-16 16:53:55 +08:00 committed by GitHub
parent 9d8489b025
commit 4d7f15b55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -1651,6 +1651,10 @@ fn (mut f Fmt) write_generic_if_require(node ast.CallExpr) {
f.write(', ')
}
}
// avoid `<Foo<int>>` => `<Foo<int> >`
if f.out.last_n(1) == '>' {
f.write(' ')
}
f.write('>')
}
}

View File

@ -0,0 +1,27 @@
struct Foo<T> {
pub:
data T
}
struct Foo1 {}
struct Foo2 {}
fn multi_generic_args<T, V>(t T, v V) bool {
return true
}
fn main() {
v1, v2 := -1, 1
// not generic
a1, a2 := v1 < v2, v2 > v1
assert a1 && a2
b1, b2 := v1 < simplemodule.zero, v2 > v1
assert b1 && b2
// generic
assert multi_generic_args<int, string>(0, 's')
assert multi_generic_args<Foo1, Foo2>(Foo1{}, Foo2{})
assert multi_generic_args<Foo<int>, Foo<int> >(Foo<int>{}, Foo<int>{})
}