Skip to content

printing expressions with Foo{<:Bar} syntax #23457

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

Closed
visr opened this issue Aug 25, 2017 · 0 comments · Fixed by #23464
Closed

printing expressions with Foo{<:Bar} syntax #23457

visr opened this issue Aug 25, 2017 · 0 comments · Fixed by #23464
Labels
display and printing Aesthetics and correctness of printed representations of objects.

Comments

@visr
Copy link
Contributor

visr commented Aug 25, 2017

#20414 introduced syntactic sugar to make Ref{<:Real} shorthand for Ref{T} where T<:Real.
Now I'm trying to print some expressions making use of this syntax, but I end up with invalid code.
In short, AST printing rule 1, parse(string(ex)) == ex, seems to be violated:

Fine for full syntax:

julia> eval(parse(string(:(Ref{T} where T<:Real))))
Ref{T} where T<:Real

It goes wrong for the shorthand:

julia> eval(parse(string(:(Ref{<:Real}))))
ERROR: unsupported or misplaced expression $
Stacktrace:
 [1] eval(::Module, ::Any) at .\boot.jl:291
 [2] eval(::Any) at .\boot.jl:290

The intermediate values look like this:

julia> Ref{<:Real}
Ref{#s1} where #s1<:Real

julia> :(Ref{<:Real})
:(Ref{$(Expr(:<:, :Real))})

julia> string(:(Ref{<:Real}))
"Ref{\$(Expr(:<:, :Real))}"

julia> parse(string(:(Ref{<:Real})))
:(Ref{$(Expr(:$, :(Expr(:<:, :Real))))})

Seen on v0.6.0 and master.

visr added a commit to visr/julia that referenced this issue Aug 26, 2017
fixes JuliaLang#23457

Previously they were not explicitly handled by show_unquoted,
ending up being printed as Expr. This was not parsable back
to their original meaning.
@ararslan ararslan added the display and printing Aesthetics and correctness of printed representations of objects. label Aug 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants