1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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) { pub fn (mut f Fmt) cast_expr(node ast.CastExpr) {
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias) + '(') 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) f.expr(node.expr)
if node.has_arg { if node.has_arg {
f.write(', ') f.write(', ')

View File

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

View File

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