v2: stringify multi-return types

pull/3820/head^2
Alexey 2020-02-24 18:38:31 +03:00 committed by GitHub
parent 2bbb8526a3
commit 87ad5a96b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -103,3 +103,11 @@ const (
'i128': true
}
)
fn fn_with_assign_stmts() {
a, b := fn_with_multi_return()
}
fn fn_with_multi_return() (int, string) {
return 0, 'test'
}

View File

@ -107,3 +107,12 @@ reserved_types = {
'i128': true
}
)
fn fn_with_assign_stmts() {
a,b := fn_with_multi_return()
}
fn fn_with_multi_return() (int,string) {
return 0,'test'
}

View File

@ -7,7 +7,7 @@ import (
strings
)
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
MultiReturn | Alias
pub struct TypeSymbol {
@ -399,6 +399,19 @@ pub mut:
pub fn (table &Table) type_to_str(t Type) string {
sym := table.get_type_symbol(t)
if sym.kind == .multi_return {
mut res := '('
mr_info := sym.info as MultiReturn
for i, typ in mr_info.types {
res += table.type_to_str(typ)
if i < mr_info.types.len - 1 {
res += ', '
}
}
res += ')'
return res
}
mut res := sym.name.replace('array_', '[]')
// mod.submod.submod2.Type => submod2.Type
if res.contains('.') {