That’s not a bug. Symbol(::String)
intentionally allows you to make a symbol out of any string as-is (as long as it does not contain '\0'
), and is intentionally not restricted to valid Julia identifiers. See the discussion in julia#5462 (at which point in time the constructor was called symbol(::String)
).
If you want to ensure a valid Julia identifier, do Meta.parse
or, better yet, use the :symbol
syntax.
That being said, I think there may be a bug in Symbol
printing stemming from a bug in Base.isidentifier
, which does not check normalization:
julia> "e\u0301" # e with acute accent, not NFC normalized
"é"
julia> Symbol("e\u0301") == :é # correct: :é is normalized
false
julia> Base.isidentifier(Symbol("e\u0301")) # incorrect: should check normalization
true
julia> Symbol("e\u0301") # incorrect display: should check normalization
:é
See Base.isidentifier(::Symbol) should check normalization · Issue #52641 · JuliaLang/julia · GitHub