-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Doc system cannot document first expression generated by macro #12705
Comments
I guess we could go with the behaviour of attaching the doc to the first expression in a block. There's some related discussion here about this kind of thing. Alternatively you could allow your macro to take a string as an argument and then use @with_kw """
...
""" immutable MT1
r::Int = 4
c = "sdaf"
end though it's not quite as elegant. |
Yes you're right, what I should have written: it used to work in the sense that no error was thrown. I didn't actually check to which expression the doc was attached. Your alternative suggestion would mean that all macro writers would also have to deal with documentation, not ideal. I think attaching to the first bit would be the best/logical thing to do. |
Would that cover all macros? Are there times when some setup code is needed prior to the main definition? ie. macro foo(...)
quote
# some setup code
# ...
$(def)
end
end @one-more-minute's |
It would cover all macros I made which I would like to use documentation with (a grand total of 3...). Linked in the issue you linked above I found where I discussed this before (I couldn't find it anymore): #12000 (comment). With that PR it was possible to document the return value of a block, which doesn't work anymore:
although single statement blocks work:
So how about, instead documenting the return value of a block/macro expansion, as was possible (I think) after PR #12000 . That would work for me. It would be a bit fiddly with methods but that is ok (for now). |
That's due to
That wouldn't allow for documenting methods, types, or constants correctly I think, since if the convention was to document the value of the block then, for example: julia> macro t()
quote
# ...
type T
end
end
end
julia> typeof(@t())
Void
julia> macro f()
quote
# ...
f() = ()
end
end
julia> typeof(@f())
Function
julia> macro c()
quote
# ...
const c = ()
end
end
julia> typeof(@c())
Tuple{}
|
If documenting the return value, one would have to be explicit to return what needs to be documented:
which would work fine for everything except methods. I would be fine with this. |
Yeah, that would work. @one-more-minute are you still against documenting arbitrary blocks? Or we could try to get the |
Also, a test is in place to be activated after fix of JuliaLang/julia#12705 [ci skip]
Also, a test is in place to be activated after fix of JuliaLang/julia#12705 [ci skip]
This adds a `@__doc__` macro, not exported currently, for use by macro authors that what their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Fixes JuliaLang#12705.
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Fixes JuliaLang#12705.
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Fixes JuliaLang#12705.
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Fixes JuliaLang#12705.
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Also improve invalid doc expression error message by displaying the unexpanded form of the expression instead of its expansion. Enable docstrings for `at-enum` using the newly added macro. Fixes JuliaLang#12705.
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Also improve invalid doc expression error message by displaying the unexpanded form of the expression instead of its expansion. Enable docstrings for `at-enum` using the newly added macro. Fixes #12705. (cherry picked from commit 0b9ef7d) ref #13006
This adds a `@__doc__` macro, not exported currently, for use by macro authors that want their macros to hook into the docsystem properly. Usage: macro example(f) quote $(f)() = 0 @__doc__ $(f)(x) = 1 $(f)(x, y) = 2 end |> esc end "Docs for `g(x)` only." @example g will attach the docstring to the 1-arg method only. Also improve invalid doc expression error message by displaying the unexpanded form of the expression instead of its expansion. Enable docstrings for `at-enum` using the newly added macro. Fixes JuliaLang#12705.
I'm pretty sure this used to work:
(
@with_kw
generates a type and the a bunch of other stuff)I would expect that
"d"
gets attached tog
, i.e. the first expression generated by the macro. I think this used to work. At least below used to work with an about 8 days old master (this is how I got to this) but now errors with the same error:The text was updated successfully, but these errors were encountered: