fmt: fix removal of `Abc` in `import mod { Abc }`, where `Abc` is used in a `x as Abc` expression #10306

pull/10341/head
zakuro 2021-06-03 12:35:54 +09:00 committed by GitHub
parent 672bb6ca7f
commit 4089aa38c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 1 deletions

View File

@ -1561,6 +1561,7 @@ fn should_decrease_arr_penalty(e ast.Expr) bool {
}
pub fn (mut f Fmt) as_cast(node ast.AsCast) {
f.mark_types_import_as_used(node.typ)
type_str := f.table.type_to_str_using_aliases(node.typ, f.mod2alias)
f.expr(node.expr)
f.write(' as $type_str')

View File

@ -1,4 +1,4 @@
import v.ast
import v.ast { InfixExpr }
import v.table
fn test_as() {

View File

@ -11,6 +11,7 @@ import mod {
InterfaceField,
InterfaceMethodArg,
InterfaceMethodRet,
RightOfAs,
RightOfIs,
StructEmbed,
StructField,
@ -37,6 +38,7 @@ interface Interface {
fn f(v FnArg) FnRet {
if v is RightOfIs {
}
_ = v as RightOfAs
return {}
}

View File

@ -21,6 +21,7 @@ import mod {
FnRet,
RightOfIs,
RightOfAs,
}
struct Struct {
@ -40,6 +41,7 @@ interface Interface {
fn f(v FnArg) FnRet {
if v is RightOfIs {}
_ = v as RightOfAs
return {}
}