v.fmt: keep selective type imports used for casting (#10597)

pull/10600/head
Lukas Neubert 2021-06-28 12:21:26 +02:00 committed by GitHub
parent 2e5ed08558
commit 1492eae27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 1 deletions

View File

@ -1720,6 +1720,7 @@ pub fn (mut f Fmt) call_args(args []ast.CallArg) {
pub fn (mut f Fmt) cast_expr(node ast.CastExpr) {
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias) + '(')
f.mark_types_import_as_used(node.typ)
f.expr(node.expr)
if node.has_arg {
f.write(', ')

View File

@ -1,5 +1,5 @@
import v.ast { InfixExpr }
import v.table
import v.table { Type }
fn test_as() {
_ := sum_expr() as InfixExpr

View File

@ -1,10 +1,12 @@
import math.complex { Complex }
import gg { MouseButton }
import time { Duration }
fn keep_imported_enum_map_key() {
bm := map[MouseButton]string{}
}
fn main() {
_ := Duration(10) // keep cast type
assert *(&f64(&byte(&num) + __offsetof(Complex, re))) == 1.0
}