v icon indicating copy to clipboard operation
v copied to clipboard

about import warning

Open lydiandy opened this issue 6 years ago • 2 comments

V version: latest:V 0.1.25 5a6f4aa OS: mac

What did you do? in my module,when I import time module,I just want to use the C function defined

pub struct C.timeval {
	tv_sec  u64
	tv_usec u64
}

I do not use any other function or struct in time module

What did you expect to see? the code can run without a warning. I think one module just only use the C function defined in the other module,It can also be treated as use the module

What did you see instead? the V compiler give me a warning:the following imports were never used: time so I have to redefine C.timeval struct in my own module

lydiandy avatar Feb 14 '20 06:02 lydiandy

tiny replication:

module main

pub struct C.aa {
	a  u64
}

pub fn main() {}

esquerbatua avatar Sep 26 '24 22:09 esquerbatua

just use:

import time as _

to avoid th warning.

looks like v does not see the c struct as belonging to time anyway as you can use it without the time. prefix.

martinskou avatar May 16 '25 12:05 martinskou

$ v run x.v
x.v:3:8: warning: module 'time' is imported but never used. Use `import time as _`, to silence this warning, or just remove the unused import line
    1 | module main
    2 | 
    3 | import time
      |        ~~~~
    4 | 
    5 | fn main() {
C.timeval{
    tv_sec: 0
    tv_usec: 0
}

StunxFS avatar Dec 07 '25 02:12 StunxFS