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

replacing a module leads to confusing errors #42109

Closed
Volker-Weissmann opened this issue Sep 3, 2021 · 1 comment
Closed

replacing a module leads to confusing errors #42109

Volker-Weissmann opened this issue Sep 3, 2021 · 1 comment

Comments

@Volker-Weissmann
Copy link
Contributor

Let's say other.jl looks something like this

module dat
    export Visible, Invisible
    struct Visible
        a::Int
    end
    struct Invisible
        a::Int
    end
end
using .dat
const var = Visible(10)

And you accidentally include this file twice (directly or indirectly):

include("other.jl")
include("other.jl")
Visible(20)
Invisible(20)

Executing this will output

WARNING: replacing module dat.
WARNING: using dat.Visible in module Main conflicts with an existing identifier.
WARNING: both dat and dat export "Invisible"; uses of it in module Main must be qualified
ERROR: LoadError: UndefVarError: Invisible not defined
Stacktrace:
 [1] top-level scope
   @ main.jl:5
in expression starting at main.jl:5

If the line const var = Visible(10) is well hidden inside mountains of code, you can look at it for a loooong time without finding the bug. Other than const var = Visible(10) the types Visible and Invisible are defined in the same way at the same point, yet one is visible and the other one is not.

It is especially confusing because something like const var = Visible(10) does not affect the visibility of a type in most other languages.

I encountered this is a real world application and I only found it by

  1. deleting some code
  2. Check if the same error message still appears. If no, un-delete this code
  3. Repeat step 1 until you have 20 lines of code that reproduce the error message.

I don't know julia well enough to know how this can be made easier to debug. Hopefully you know.

@vtjnash
Copy link
Member

vtjnash commented Sep 3, 2021

I'm am not quite sure what you are suggesting to fix, since it output numerous warnings for when it ran into errors with your code. Perhaps we could print more context there, like the backtrace?

@vtjnash vtjnash changed the title language design leads to some very hard to debug problems replacing a module leads to confusing errors Sep 3, 2021
@vtjnash vtjnash closed this as completed Oct 31, 2023
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

No branches or pull requests

2 participants