Skip to content

Base.@doc in macro doesn't work on master #52986

@Tortar

Description

@Tortar
Contributor

As the title says this seems to be the case because in a PR on SumTypes.jl (https://github.com/MasonProtter/SumTypes.jl/pull/63/files) the doctest failing is only on nightly, while all the other works well, as you can see at https://github.com/MasonProtter/SumTypes.jl/actions/runs/7595253256/job/20687608559 the test fails with

Basics  : Test Failed at /home/runner/work/SumTypes.jl/SumTypes.jl/test/runtests.jl:40
  Expression: string(#= /home/runner/work/SumTypes.jl/SumTypes.jl/test/runtests.jl:40 =# @doc(Foo)) == "This is a Foo.\n"
   Evaluated: "nothing" == "This is a Foo.\n"

while for all other Julia versions it returns "This is a Foo.\n". Same is happening also on the CI of ProtoStructs.jl e.g. here https://github.com/BeastyBlacksmith/ProtoStructs.jl/actions/runs/7500520539/job/20419369109

Unfortunately I wasn't able to find a MWE when I searched for it

Activity

vtjnash

vtjnash commented on Jan 20, 2024

@vtjnash
SponsorMember

This is a REPL-only feature. Packages should normally be using @ref links, not copying the text from elsewhere. E.g.:

$ ./julia -E '@doc Base'
nothing
$ ./julia -E 'using REPL; @doc Base'
```
Base
```

The base library of Julia. `Base` is a module that contains basic functionality (the contents of `base/`). All modules implicitly contain `using Base`, since this is needed in the vast majority of cases.
KristofferC

KristofferC commented on Jan 20, 2024

@KristofferC
Member

This doesn't make sense to me... Why would the docsystem work differently if the REPL is loaded? Seems something should be moved back to Base.

jmert

jmert commented on Jan 23, 2024

@jmert
Contributor

See also #52141.

added this to the 1.11 milestone on Mar 4, 2024
added
docsThis change adds or pertains to documentation
regressionRegression in behavior compared to a previous version
on Mar 4, 2024
JamesWrigley

JamesWrigley commented on Mar 6, 2024

@JamesWrigley
Contributor

This also hit the Clang.jl tests. Here's a MWE:

doc_expr = (@macroexpand @doc throw)
docstring = string(@doc throw)

@show Base.hasdoc(Main, :throw)
@show doc_expr
@show docstring

And the output on v1.11 alpha

$ julia +1.11 --startup-file=no mwe.jl
Base.hasdoc(Main, :throw) = true
doc_expr = nothing
docstring = "nothing"

Vs 1.10.2 (without Base.hasdoc()):

$ julia --startup-file=no mwe.jl
doc_expr = :((Base.Docs.doc)((Base.Docs.Binding)(Main, :throw)))
docstring = "```\nthrow(e)\n```\n\nThrow an object as an exception.\n\nSee also: [`rethrow`](@ref), [`error`](@ref).\n"

It looks like the macro is returning a nothing value instead of an Expr?

KristofferC

KristofferC commented on Mar 6, 2024

@KristofferC
Member

One issue with this is that @doc gives you are markdown object, which is defined in another stdlib.

24 remaining items

JamesWrigley

JamesWrigley commented on Sep 2, 2024

@JamesWrigley
Contributor

(bump)

JamesWrigley

JamesWrigley commented on Sep 9, 2024

@JamesWrigley
Contributor

@KristofferC, @JeffBezanson, apologies for the direct ping but I think this isn't fully fixed yet. Could it be reopened?

JeffBezanson

JeffBezanson commented on Sep 17, 2024

@JeffBezanson
SponsorMember

I have a fix.

The docsystem design really has problems. For example in this case @time can take either one or two arguments, so those are its valid "signatures" according to the docsystem. And @doc @time is asking about zero arguments, so there are no matches. BUT that's the syntax for asking for help for any arguments, so there's a rule that you have to return all of the matches if there aren't any. I mean it kind of makes sense in terms of "helpfulness", but the way it's implemented we can't distinguish between asking for all the docs for something, and asking for something that doesn't exist like sin with 7 arguments.

lgoettgens

lgoettgens commented on Sep 17, 2024

@lgoettgens
Contributor

Does your fix, by any chance, also fix #52986 (comment) and thus #54664 as well?

added a commit that references this issue on Sep 17, 2024
0162588
JeffBezanson

JeffBezanson commented on Sep 17, 2024

@JeffBezanson
SponsorMember

No it does not. We can think about what to do about that separately.

KristofferC

KristofferC commented on Sep 19, 2024

@KristofferC
Member

I think we discussed @doc always returning a String which the REPL then parses into Markdown to display.

added a commit that references this issue on Sep 19, 2024
4045e7b
added 2 commits that reference this issue on Sep 24, 2024
b0bf394
a28592d
added a commit that references this issue on Oct 14, 2024
d3f4808
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsThis change adds or pertains to documentationregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @vtjnash@ztangent@JeffBezanson@KristofferC@jmert

    Issue actions

      `Base.@doc` in macro doesn't work on master · Issue #52986 · JuliaLang/julia