# Question About Unicode and Symbols

**URL:** <https://discourse.julialang.org/t/question-about-unicode-and-symbols/108080>\
**Category:** General Usage\
**Tags:** strings, struct, unicode\
**Created:** [December 27, 2023, 3:26am UTC](https://discourse.julialang.org/t/question-about-unicode-and-symbols/108080 "2023-12-27T03:26:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Post date:** [December 27, 2023, 3:26am UTC](https://discourse.julialang.org/t/question-about-unicode-and-symbols/108080/1 "2023-12-27T03:26:08Z")

</div>

Hello

I’ve been experimenting with overloading `getproperty` for some structs in a personal project of mine.

I noticed the following throws an error (using `getfield` instead of `getproperty` in this MWE).

Does anyone know why? I type the u-bar in the REPL by typing `u\bar` then pressing tab.

```julia

struct MyStruct
    ū::Vector{Float64}
end

tmp = MyStruct(rand(5))

tmp.ū # no error
getfield(tmp, :ū) # no error
getfield(tmp, Symbol("ū")) # throws error, type MyStruct has no field ū

```

So it seems that `:ū == Symbol("ū")` is `false`.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 27, 2023, 3:46am UTC](https://discourse.julialang.org/t/question-about-unicode-and-symbols/108080/2 "2023-12-27T03:46:05Z")

</div>

This has to do with unicode normalization and might be a bug? Specifically,

```julia
julia> codeunits(String(:ū))
2-element Base.CodeUnits{UInt8, String}:
 0xc5
 0xab

julia> codeunits("ū")
3-element Base.CodeUnits{UInt8, String}:
 0x75
 0xcc
 0x84

```

Julia normalizes symbols, but aparently doesn’t do so when you call `Symbol(::String)`:

```julia
julia> codeunits(String(Symbol("ū")))
3-element Base.CodeUnits{UInt8, String}:
 0x75
 0xcc
 0x84

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 27, 2023, 2:05pm UTC](https://discourse.julialang.org/t/question-about-unicode-and-symbols/108080/3 "2023-12-27T14:05:53Z")

</div>

> [@Oscar\_Smith](#):
>
> Julia normalizes symbols, but aparently doesn’t do so when you call `Symbol(::String)`:

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](https://github.com/JuliaLang/julia/pull/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
julia> "e\u0301" # e with acute accent, not NFC normalized
"é"

julia> Symbol("e\u0301") == :é # correct: :é is normalized
false

julia> Base.isidentifier(Symbol("e\u0301")) # incorrect: should check normalization
true

julia> Symbol("e\u0301") # incorrect display: should check normalization
:é

```

See [Base.isidentifier(::Symbol) should check normalization · Issue #52641 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/52641)
