From 5b041db44298bf8ed9c0b8024450fb43411ffc42 Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 4 Mar 2021 19:33:52 +0900 Subject: [PATCH] fmt: don't prepend mod when cast with selective imported types (#9109) --- vlib/v/fmt/fmt.v | 4 ++-- vlib/v/fmt/tests/cast_expected.vv | 9 +++++++-- vlib/v/fmt/tests/cast_input.vv | 10 ++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 3ed4d1ac68..162edc460b 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1157,13 +1157,13 @@ pub fn (mut f Fmt) fn_decl(node ast.FnDecl) { } pub fn (mut f Fmt) as_cast(node ast.AsCast) { - type_str := f.table.type_to_str(node.typ) + type_str := f.table.type_to_str_using_aliases(node.typ, f.mod2alias) f.expr(node.expr) f.write(' as $type_str') } pub fn (mut f Fmt) cast_expr(node ast.CastExpr) { - f.write(f.table.type_to_str(node.typ) + '(') + f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias) + '(') f.expr(node.expr) if node.has_arg { f.write(', ') diff --git a/vlib/v/fmt/tests/cast_expected.vv b/vlib/v/fmt/tests/cast_expected.vv index b16b09ee98..7f6a15ecdf 100644 --- a/vlib/v/fmt/tests/cast_expected.vv +++ b/vlib/v/fmt/tests/cast_expected.vv @@ -1,8 +1,13 @@ +import v.ast +import v.table + fn test_as() { - a := sum_expr() as Bar - _ := a + _ := sum_expr() as InfixExpr + _ := sum_expr() as ast.PrefixExpr } fn test_cast() { _ := f32(0) + _ := Type(0) + _ := ast.Expr(sum_expr()) } diff --git a/vlib/v/fmt/tests/cast_input.vv b/vlib/v/fmt/tests/cast_input.vv index a51a0f1c74..72b254cde8 100644 --- a/vlib/v/fmt/tests/cast_input.vv +++ b/vlib/v/fmt/tests/cast_input.vv @@ -1,8 +1,14 @@ +import v.ast { InfixExpr } +import v.table { Type } + fn test_as() { - a := sum_expr() as Bar - _ := a + _ := sum_expr() as ast.InfixExpr + _ := sum_expr() as ast.PrefixExpr } fn test_cast() { _ := f32(0) + _ := table.Type(0) + _ := ast.Expr(sum_expr()) } +