ExplicitImports.jl icon indicating copy to clipboard operation
ExplicitImports.jl copied to clipboard

imported name shadowed by field name

Open kuszmaul opened this issue 6 months ago • 1 comments

Suppose I have a module

module Atest

hello() = "Hello, World!"

end # module

And another module

module Btest

using Atest: hello

struct Foo
    hello::String
    Foo() = new(hello())
end

end # module

Then I get

julia> using ExplicitImports, Btest
julia> print_explicit_imports(Btest)
  Module Btest is not relying on any implicit imports.

  However, module Btest has stale explicit imports for this 1 unused name:

    •  hello is unused but it was imported from Atest at
       /home/ubuntu/raicode-master/raicode/packages/Btest/src/Btest.jl:3:14

which is incorrect. hello is used in the constructor for Foo().

If I rename the field in Foo to, say hello2, then I don't get the warning

module Ctest

using Atest: hello

struct Foo
    hello2::String
    Foo() = new(hello())
end

end # module

tests ok:

julia> print_explicit_imports(Ctest)
  Module Ctest is not relying on any implicit imports.

julia>

kuszmaul avatar Jun 13 '25 14:06 kuszmaul

yeah, this is one that will hopefully be solved by switching to JuliaLowering. Our scope resolution isn't good enough to realize that the hello in the constructor is not referring to a field. We could probably improve it case-by-case but eventually we will just reimplement a bunch of lowering that is already being developed in JuliaLowering, so I'd rather devote the effort to switching to using JuliaLowering.

In the meantime, if you use the check_ functions, you can tell them to ignore this using the kwargs.

ericphanson avatar Jun 13 '25 16:06 ericphanson