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

Undesirable Main.var"Main" qualification of new modules #2541

Open
timholy opened this issue Jul 2, 2024 · 2 comments
Open

Undesirable Main.var"Main" qualification of new modules #2541

timholy opened this issue Jul 2, 2024 · 2 comments

Comments

@timholy
Copy link
Contributor

timholy commented Jul 2, 2024

In brief,

```jldoctest
module NewModule
end

# output

NewModule
```

fails, and Documenter thinks it should be printed Main.var"Main".NewModule. Adding setup=:(using Main) does not seem to help. Any suggestions?

The error message below is from the SnoopCompile docs.

┌ Error: doctest failure in src/snoop_inference.md:20-42
│
│ ```jldoctest flatten-demo
│ module FlattenDemo
│     struct MyType{T} x::T end
│
│     extract(y::MyType) = y.x
│
│     function domath(x)
│         y = x + x
│         return y*x + 2*x + 5
│     end
│
│     dostuff(y) = domath(extract(y))
│
│     function packintype(x)
│         y = MyType{Int}(x)
│         return dostuff(y)
│     end
│ end
│
│ # output
│
│ FlattenDemo
│ ```
│
│ Subexpression:
│
│ module FlattenDemo
│     struct MyType{T} x::T end
│
│     extract(y::MyType) = y.x
│
│     function domath(x)
│         y = x + x
│         return y*x + 2*x + 5
│     end
│
│     dostuff(y) = domath(extract(y))
│
│     function packintype(x)
│         y = MyType{Int}(x)
│         return dostuff(y)
│     end
│ end
│
│ Evaluated output:
│
│ Main.var"Main".FlattenDemo
│
│ Expected output:
│
│ FlattenDemo
│
│   diff = FlattenDemoMain.var"Main".FlattenDemo
└ @ Documenter src/snoop_inference.md:20
@timholy
Copy link
Contributor Author

timholy commented Jul 6, 2024

What's also weird is that filtering doesn't seem to fix it. Here you can see the filter I used on the top line of the quoted section:

julia> include("docs/make.jl")
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
┌ Error: doctest failure in src/snoop_inference.md:20-42
│
│ ```jldoctest flatten-demo; filter=r"Main\.var\"Main\"\."
│ module FlattenDemo
│     struct MyType{T} x::T end
│
│     extract(y::MyType) = y.x
│
│     function domath(x)
│         y = x + x
│         return y*x + 2*x + 5
│     end
│
│     dostuff(y) = domath(extract(y))
│
│     function packintype(x)
│         y = MyType{Int}(x)
│         return dostuff(y)
│     end
│ end
│
│ # output
│
│ FlattenDemo
│ ```
│
│ Subexpression:
│
│ module FlattenDemo
│     struct MyType{T} x::T end
│
│     extract(y::MyType) = y.x
│
│     function domath(x)
│         y = x + x
│         return y*x + 2*x + 5
│     end
│
│     dostuff(y) = domath(extract(y))
│
│     function packintype(x)
│         y = MyType{Int}(x)
│         return dostuff(y)
│     end
│ end
│
│ Evaluated output:
│
│ Main.var"Main".FlattenDemo
│
│ Expected output:
│
│ FlattenDemo
│
│   diff = FlattenDemoMain.var"Main".FlattenDemo
└ @ Documenter src/snoop_inference.md:20

@fredrikekre
Copy link
Member

Documenter doesn't evaluate in Main but in a new anonymous module. To then simulate being in Main any references to the anonymous module is filtered out. Perhaps something is wrong in this process, I haven't looked into the details yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants