Open Elsie19 opened 6 days ago
Imported module name can be aliased using the
as
keyword You cannot alias an imported function or type. However, you can redeclare a type.
Thus the below would work, for the case presented.
import qbe as kind // {Type}
type Type = kind.Type
fn main() {
println(kind.Type.word.str())
println(Type.word.str())
}
or
import qbe
fn main() {
println(qbe.Type.word.str())
}
However, I do think team V may want to be careful about pushing modules into the same category as unused variables. As I have come across older modules (that were listed on VPM) that worked on a previous version of V, but then gave the "unused module" error as described above, on newer V versions. It should be clear that a programmer may not use everything from an imported module.
You don't have to use everything from an imported module, but you do need to use something.
In this case, it's just a bug that it didn't count it as used.
What you are saying should be true, but If I remember correctly, this could pertain to a module with multiple files and referencing other modules as well. I would have to go back and investigate again, as had worked around the issue. But mentioning it, as seeing "unused module" jarred my memory.
You can do import mod as _
, if you want to import it, just for the side effects (due to potential const initialisations that call functions, or the module's init function), without using any symbols.
The issue is indeed just a bug - because the symbol Type
is used in the user code later.
The compiler should note that, and not trigger a warning at all in this case.
Describe the bug
When I create a local module and selectively import something from it, v will complain about the module being imported but unused even though I selectively imported something from it. While this is technically true, it doesn't make much sense from a developer perspective, as using any publicly available code from the module should count as using the module.
Reproduction Steps
src/lib.v
:src/main.v
:v.mod
:Expected Behavior
I should not get a warning about the module being imported but unused when I use any code inside that module, as using that code should count as using the module.
Current Behavior
When doing
v run .
, I get the warning:Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.8 b801083
Environment details (OS name and version, etc.)
V full version: V 0.4.8 1931811.b801083 OS: linux, Ubuntu 24.10 Processor: 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz
getwd: /home/henry/Projects/v/qbe vexe: /home/henry/Projects/v/vcompiler/v vexe mtime: 2024-11-25 18:10:30
vroot: OK, value: /home/henry/Projects/v/vcompiler VMODULES: OK, value: /home/henry/.vmodules VTMP: OK, value: /tmp/v_1000
Git version: git version 2.45.2 Git vroot status: b801083f (4 commit(s) behind V master) .git/config present: true
CC version: cc (Ubuntu 14.2.0-4ubuntu2) 14.2.0 emcc version: N/A thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9
Huly®: V_0.6-21416