9942 commits 0 issues 0 pull requests 439 contributors 0 branches 0 releases
Additions: 33 Deletions: 7
vlib/v/ast/types.v
1
2 // import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
3 pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
4- /*
5- if t.pref.is_verbose {
6- print_backtrace()
7- exit(0)
8- }
9- */
10 sym := t.get_type_symbol(typ)
11 mut res := sym.name
12 match sym.kind {
13 res = t.shorten_user_defined_typenames(res, import_aliases)
14 }
15 }
16+ .generic_struct_inst {
17+ info := sym.info as GenericStructInst
18+ res = sym.name.all_before('<')
19+ res += '<'
20+ for i, ctyp in info.concrete_types {
21+ res += t.get_type_symbol(ctyp).name
22+ if i != info.concrete_types.len - 1 {
23+ res += ', '
24+ }
25+ }
26+ res += '>'
27+ res = t.shorten_user_defined_typenames(res, import_aliases)
28+ }
29 .void {
30 if typ.has_flag(.optional) {
31 return '?'
32
vlib/v/fmt/tests/generics_keep.vv
1+import mymod { ImpNode }
2+
3+fn foobar_mymod<U>(inode ImpNode<U>) ImpNode<U> {
4+ return ImpNode{}
5+}
6+
7 fn simple<T>() T {
8 return T{}
9 }
10 return T{}
11 }
12
13+struct NonGenericStruct {}
14+
15+fn use_as_generic(ngs NonGenericStruct<V>) NonGenericStruct<V> {
16+ return NonGenericStruct{}
17+}
18+
19+struct GenericStruct<A, B> {}
20+
21+fn proper_generics(gs GenericStruct<A, B>) GenericStruct<A, B> {
22+ return gs
23+}
24+
25 fn main() {
26 simple<int>()
27 Foo{}.simple<int>()
28
vlib/v/parser/parse_type.v
1 p.check(.gt)
2 p.in_generic_params = false
3 bs_name += '>'
4- if is_instance && concrete_types.len > 0 {
5+ // fmt operates on a per-file basis, so is_instance might be not set correctly. Thus it's ignored.
6+ if (is_instance || p.pref.is_fmt) && concrete_types.len > 0 {
7 mut gt_idx := p.table.find_type_idx(bs_name)
8 if gt_idx > 0 {
9 return ast.new_type(gt_idx)
10