Skip to content

Commit 9404ef7

Browse files
committed
Extend static_show() escaping to any illegal identifier via var"".
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) ```
1 parent 04bfa32 commit 9404ef7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/rtutils.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,10 @@ static size_t jl_static_show_x_sym_escaped(JL_STREAM *out, jl_sym_t *name) JL_NO
625625
size_t n = 0;
626626

627627
char *sn = jl_symbol_name(name);
628-
int hidden = strchr(sn, '#') != 0;
628+
int hidden = 0;
629+
if (!jl_is_identifier(sn) || jl_is_operator(sn)) {
630+
hidden = 1;
631+
}
629632

630633
if (hidden) {
631634
n += jl_printf(out, "var\"");

test/show.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ end
13391339
# PR #38049
13401340
struct var"#X#" end
13411341
var"#f#"() = 2
1342+
struct var"%X%" end # Invalid name without '#'
13421343

13431344
@test static_shown(var"#X#") == "Main.var\"#X#\""
13441345
# (Just to make this test more sustainable,) for types, we don't necesssarily need to test
@@ -1350,6 +1351,8 @@ var"#f#"() = 2
13501351
@testset for v in (
13511352
var"#X#",
13521353
var"#X#"(),
1354+
var"%X%",
1355+
var"%X%"(),
13531356
Vector,
13541357
Vector{<:Any},
13551358
Vector{var"#X#"},

0 commit comments

Comments
 (0)