diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 8cee1c8cbe..42f23efb92 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1651,6 +1651,10 @@ fn (mut f Fmt) write_generic_if_require(node ast.CallExpr) { f.write(', ') } } + // avoid `>` => ` >` + if f.out.last_n(1) == '>' { + f.write(' ') + } f.write('>') } } diff --git a/vlib/v/fmt/tests/generics_cascade_types_keep.vv b/vlib/v/fmt/tests/generics_cascade_types_keep.vv new file mode 100644 index 0000000000..82fd8dd3f2 --- /dev/null +++ b/vlib/v/fmt/tests/generics_cascade_types_keep.vv @@ -0,0 +1,27 @@ +struct Foo { +pub: + data T +} + +struct Foo1 {} + +struct Foo2 {} + +fn multi_generic_args(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(0, 's') + assert multi_generic_args(Foo1{}, Foo2{}) + assert multi_generic_args, Foo >(Foo{}, Foo{}) +}