fmt: optionals; none

pull/3806/head
Alexander Medvednikov 2020-02-21 17:52:20 +01:00
parent d075be73e8
commit 9e6773cba8
4 changed files with 15 additions and 4 deletions

View File

@ -304,6 +304,9 @@ fn (f mut Fmt) expr(node ast.Expr) {
}
f.write(')')
}
ast.None {
f.write('none')
}
ast.PostfixExpr {
f.expr(it.expr)
f.write(it.op.str())

View File

@ -69,3 +69,7 @@ fn (this User) fn_with_receiver() {
x := if true { 1 } else { 2 }
println('')
}
fn get_user() ?User {
return none
}

View File

@ -74,6 +74,6 @@ fn (this User) fn_with_receiver() {
println('')
}
//fn get_user() ? User {
//}
fn get_user() ? User {
return none
}

View File

@ -395,5 +395,9 @@ pub mut:
pub fn (table &Table) type_to_str(t Type) string {
sym := table.get_type_symbol(t)
return sym.name.replace('array_', '[]')
mut res := sym.name.replace('array_', '[]')
if type_is_optional(t) {
res = '?' + res
}
return res
}