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

Docstrings with backslashes yield "invalid escape sequence" upon precompilation #29200

Closed
timholy opened this issue Sep 15, 2018 · 3 comments
Closed

Comments

@timholy
Copy link
Member

timholy commented Sep 15, 2018

Non-contaminating reproducer: start julia with

$ DEPOT_PATH=/tmp/pkgs julia

and then

(v1.0) pkg> generate Backslash
Generating project Backslash:
    Backslash/Project.toml
    Backslash/src/Backslash.jl

julia> edit("Backslash/src/Backslash.jl")

Then add a docstring to greet:

"""
This is a docstring with a backslash: x = A \ b
"""
greet() = print("Hello World!")

(I inserted the spaces between backticks to prevent confusing the markdown renderer here, but you should take them out when you try this.)

And then finally:

julia> using Backslash
[ Info: Precompiling Backslash [f5b45752-b8ef-11e8-19fb-2fec647fc92b]
ERROR: LoadError: syntax: invalid escape sequence
Stacktrace:
 [1] include at ./boot.jl:317 [inlined]
 [2] include_relative(::Module, ::String) at ./loading.jl:1041
 [3] include(::Module, ::String) at ./sysimg.jl:29
 [4] top-level scope at none:2
 [5] eval at ./boot.jl:319 [inlined]
 [6] eval(::Expr) at ./client.jl:389
 [7] top-level scope at ./none:3
in expression starting at /tmp/Backslash/src/Backslash.jl:5
ERROR: Failed to precompile Backslash [f5b45752-b8ef-11e8-19fb-2fec647fc92b] to /tmp/pkgs/compiled/v1.0/Backslash/JC5Xv.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] macro expansion at ./logging.jl:313 [inlined]
 [3] compilecache(::Base.PkgId, ::String) at ./loading.jl:1187
 [4] _require(::Base.PkgId) at ./logging.jl:311
 [5] require(::Base.PkgId) at ./loading.jl:855
 [6] macro expansion at ./logging.jl:311 [inlined]
 [7] require(::Module, ::Symbol) at ./loading.jl:837

Now, perhaps this is deliberate (you can fix it by changing \ to \\), but it seems a little strange to have precompilation fail due to the formatting of the docstring.

@yuyichao
Copy link
Contributor

But "A \ b" isn't a valid string and the doc string is just a string. Why would invalid string as docstring not cause an error?

Also, no need to create a package, REPL is enough...

julia> """
       This is a docstring with a backslash: x = A \ b
       """
       greet() = print("Hello World!")

ERROR: syntax: invalid escape sequence

@timholy
Copy link
Member Author

timholy commented Sep 15, 2018

Fair enough. There isn't a depwarn for 0.7 or FemtoCleaner fix, but I'll close.

@timholy timholy closed this as completed Sep 15, 2018
@fredrikekre
Copy link
Member

See #22800

You can use

using Markdown
@doc doc"""
This is a docstring with a backslash: x = A \ b
"""
greet() = print("Hello World!")

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

3 participants