Skip to content
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

Adds support for String(x::Symbol) = string(x) #18152

Merged
merged 1 commit into from
Sep 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement convert(::Type{String}, x::Symbol)
This is the underlying support for calling String(::Symbol).
Bug fix for issue #16997
  • Loading branch information
dbeach24 committed Sep 18, 2016
commit 431961d9966c3c2da72763a8bbb3fa3728abec88
1 change: 1 addition & 0 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ convert(::Type{Array{UInt8}}, s::AbstractString) = String(s).data
convert(::Type{String}, s::AbstractString) = String(s)
convert(::Type{Vector{Char}}, s::AbstractString) = collect(s)
convert(::Type{Symbol}, s::AbstractString) = Symbol(s)
convert(::Type{String}, s::Symbol) = unsafe_string(Cstring(s))

## generic supplied functions ##

Expand Down
1 change: 1 addition & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let
# make symbol with invalid char
sym = Symbol(Char(0xdcdb))
@test string(sym) == string(Char(0xdcdb))
@test String(sym) == string(Char(0xdcdb))
@test expand(sym) === sym
res = string(parse(string(Char(0xdcdb)," = 1"),1,raise=false)[1])
@test res == """\$(Expr(:error, "invalid character \\\"\\udcdb\\\"\"))"""
Expand Down