vfmt: keep `module mymodule ... x := []thread MyStruct{}` as it is

pull/10772/head
Delyan Angelov 2021-07-12 10:40:11 +03:00
parent 5c7881feb7
commit 974737f26b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 31 additions and 1 deletions

View File

@ -865,6 +865,15 @@ pub fn (mytable &Table) type_to_code(t Type) string {
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
sym := t.get_type_symbol(typ)
mut res := sym.name
// Note, that the duplication of code in some of the match branches here
// is VERY deliberate. DO NOT be tempted to use `else {}` instead, because
// that strongly reduces the usefullness of the exhaustive checking that
// match does.
// Using else{} here led to subtle bugs in vfmt discovered *months*
// after the original code was written.
// It is important that each case here is handled *explicitly* and
// *clearly*, and that when a new kind is added, it should also be handled
// explicitly.
match sym.kind {
.int_literal, .float_literal {
res = sym.name
@ -989,7 +998,11 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
}
return 'void'
}
else {
.thread {
res = 'thread ' +
t.type_to_str_using_aliases(sym.thread_info().return_type, import_aliases)
}
.alias, .any, .sum_type, .interface_, .size_t, .aggregate, .placeholder, .enum_ {
res = t.shorten_user_defined_typenames(res, import_aliases)
}
}

View File

@ -0,0 +1,17 @@
module my_module
import another
import other as ooo
pub fn do_something() {
mut simples := []MyStruct{}
//
mut threads := []thread MyStruct{}
threads.wait()
//
mut another_threads := []thread another.MyStruct{}
another_threads.wait()
//
mut other_threads := []thread ooo.MyStruct{}
other_threads.wait()
}