Skip to content

Commit

Permalink
Extend static_show() escaping to any illegal identifier via var"".
Browse files Browse the repository at this point in the history
Previously, it was only escaping names with a `#` in them, but now it
will escape all names that are illegal identifiers.

Before:
```julia
julia> struct var"a%b+c" x::Int end

julia> println(static_shown(var"a%b+c"))
Main.a%b+c

julia> println(static_shown(var"a%b+c"(1)))
Main.a%b+c(x=1)
```
After:
```julia
julia> struct var"a%b+c" x::Int end

julia> println(static_shown(var"a%b+c"))
Main.var"a%b+c"

julia> println(static_shown(var"a%b+c"(1)))
Main.var"a%b+c"(x=1)
```
  • Loading branch information
NHDaly committed Oct 16, 2020
1 parent 04bfa32 commit 9404ef7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,10 @@ static size_t jl_static_show_x_sym_escaped(JL_STREAM *out, jl_sym_t *name) JL_NO
size_t n = 0;

char *sn = jl_symbol_name(name);
int hidden = strchr(sn, '#') != 0;
int hidden = 0;
if (!jl_is_identifier(sn) || jl_is_operator(sn)) {
hidden = 1;
}

if (hidden) {
n += jl_printf(out, "var\"");
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ end
# PR #38049
struct var"#X#" end
var"#f#"() = 2
struct var"%X%" end # Invalid name without '#'

@test static_shown(var"#X#") == "Main.var\"#X#\""
# (Just to make this test more sustainable,) for types, we don't necesssarily need to test
Expand All @@ -1350,6 +1351,8 @@ var"#f#"() = 2
@testset for v in (
var"#X#",
var"#X#"(),
var"%X%",
var"%X%"(),
Vector,
Vector{<:Any},
Vector{var"#X#"},
Expand Down

0 comments on commit 9404ef7

Please sign in to comment.