Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: warn and don't import when two usings provide the same name #10951

Merged
merged 1 commit into from
Apr 24, 2015

Conversation

JeffBezanson
Copy link
Member

fixes #4345

Does the following:

julia> module A
       export foo
       foo() = 1
       end

julia> module B
       export foo
       foo() = 2
       end

julia> using A

julia> using B

julia> foo()
Warning: both B and A export foo; uses of it in module Main must be qualified
ERROR: UndefVarError: foo not defined

importall is a bit of a different story. It's hard to provide the same behavior there, since it's an imperative: the names are imported right when the importall statement runs. Fortunately it's used far less often than using, and we already give a warning for conflicts in that case.

Will update news and docs if this is to be merged.

@StefanKarpinski
Copy link
Member

Awesome.

@timholy
Copy link
Member

timholy commented Apr 23, 2015

I'm a fan.

@Keno
Copy link
Member

Keno commented Apr 23, 2015

What happens with:

using A
foo()
using B
foo()

?

@JeffBezanson
Copy link
Member Author

You get Warning: using B.foo in module Main conflicts with an existing identifier. after using B, and foo() continues to call A.foo.

@toivoh
Copy link
Contributor

toivoh commented Apr 23, 2015 via email

@StefanKarpinski
Copy link
Member

I'm all for just merging this.

@kmsquire
Copy link
Member

+1

On Thursday, April 23, 2015, Stefan Karpinski [email protected]
wrote:

I'm all for just merging this.


Reply to this email directly or view it on GitHub
#10951 (comment).

JeffBezanson added a commit that referenced this pull request Apr 24, 2015
RFC: warn and don't import when two `usings` provide the same name
@JeffBezanson JeffBezanson merged commit ad7ed5d into master Apr 24, 2015
@ivarne
Copy link
Member

ivarne commented Apr 24, 2015

Great!

Remember the NEWS.md and docs.

@dcjones
Copy link
Contributor

dcjones commented Apr 24, 2015

While I think this is a good idea, it breaks Gadfly since it, as well as Base, export something called Stat. Base.Stat is deprecated though. Would it be reasonable to remove it now?

@JeffBezanson
Copy link
Member Author

Yes I think we can remove that. We'll probably remove all the 0.3 deprecations pretty soon.

@IainNZ
Copy link
Member

IainNZ commented Apr 24, 2015

Interesting examples of breakages:
http://pkg.julialang.org/?pkg=Digits&ver=nightly

Warning: both Digits and Base export contains; uses of it in module Main must be qualified
ERROR: LoadError: test error in expression: contains(n,3456) == true
UndefVarError: contains not defined
 in anonymous at test.jl:87
 in do_test at test.jl:47
 in include at ./boot.jl:250
 in include_from_node1 at loading.jl:129
 in process_options at ./client.jl:308
 in _start at ./client.jl:407
while loading /home/vagrant/testpkg/v0.4/Digits/test/runtests.jl, in expression starting on line 36

http://pkg.julialang.org/?pkg=Calculus&ver=nightly

>>> test log
Warning: both Calculus and Base export gradient; uses of it in module Main must be qualified
ERROR: LoadError: LoadError: UndefVarError: gradient not defined
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in anonymous at no file:19
 in include at ./boot.jl:250
 in include_from_node1 at loading.jl:129
 in process_options at ./client.jl:308
 in _start at ./client.jl:407

@IainNZ
Copy link
Member

IainNZ commented Apr 24, 2015

More worryingly:

>>> 'using HttpServer' log
Warning: both Docile and Base export @doc; uses of it in module HttpServer must be qualified
WARNING: Dict-based `@docstring` config is deprecated. Use keywords instead.
ERROR: LoadError: LoadError: UndefVarError: @doc not defined
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in reload_path at ./loading.jl:153
 in _require at ./loading.jl:68
 in require at ./loading.jl:51
 in include at ./boot.jl:250
 in include_from_node1 at loading.jl:129
 in process_options at ./client.jl:308
 in _start at ./client.jl:407

if (owner != NULL && tempb->owner != b->owner &&
!(tempb->constp && tempb->value && b->constp && b->value == tempb->value)) {
jl_printf(JL_STDERR,
"Warning: both %s and %s export %s; uses of it in module %s must be qualified\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the examples posted from PkgEvaluator, some quotation marks here might aid readability?

"Warning: both `%s` and `%s` export `%s`; ..."

The ones for the modules are less needed, but setting off the method name seems like it would make this a tad easier to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that'd be a nice little change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So apparently that option to "create a pull request" in the GitHub editor doesn't actually work. Nice. ec99e37

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow I had no idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what? It just makes the change instead of creating a PR? That's broken and dangerous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's an incredibly bad bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intend to reproduce it + file a report with them when I get home, if no one beats me to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And failed to reproduce. Blargh. Sorry, either I misclicked or it's specific to the Firefox (or profile, or cookies, or...) at the office.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So apparently that option to "create a pull request" in the GitHub editor doesn't actually work. Nice. ec99e37

if you have direct rights to a repo, it'll let you edit any file directly in the browser. it can be very useful for doc and README changes, but generally not so good for code edits

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware; I've fixed doc typos that way before.

GitHub appears to have recently added the ability to make a branch & pull request instead, which is what I tried to do precisely because it was a code change. It's a radio button option that appears in the edit window below the commit message box. It worked fine the second time I tried it, so I'm not sure what happened the first time.

@simonster
Copy link
Member

This is a bit annoying:

julia> using Base.Libdl

julia> dlopen
Warning: both `Libdl` and `Base` export `dlopen`; uses of it in module `Main` must be qualified
ERROR: UndefVarError: dlopen not defined

(The dlopen function exported by Base is deprecated.)

@tkelman
Copy link
Contributor

tkelman commented Apr 26, 2015

from JuliaPackaging/BinDeps.jl#143 (comment)

Should the warning maybe not happen when all imports refer to the same object? I.e. When they are === to each other?

simonster added a commit to JuliaInterop/MATLAB.jl that referenced this pull request Apr 26, 2015
simonster added a commit to JuliaStats/GLM.jl that referenced this pull request Apr 26, 2015
@JeffBezanson
Copy link
Member Author

Unless I messed up, I believe I already implemented that. However Base.dlopen !== Libdl.dlopen. They're separate functions. One prints a warning, the other does dlopen. We'll have to find a solution to this. Maybe instead of a function deprecation, we can add the warning to UndefVarError.

simonster added a commit to JuliaInterop/ZMQ.jl that referenced this pull request Apr 30, 2015
stevengj added a commit to JuliaInterop/ZMQ.jl that referenced this pull request May 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

using/importall: clashing names should be dropped