Skip to content

REPL: Convert char to string before calling escape_string#61143

Open
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/repl-add_nested_key-escapestring
Open

REPL: Convert char to string before calling escape_string#61143
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/repl-add_nested_key-escapestring

Conversation

@DilumAluthge
Copy link
Member

In this function, key is allowed to be either String or Char, but there is no method matching escape_string(::Char). So convert key to a string before calling escape_string.

MWE:

import REPL

keymap = Dict{Char, Any}()
REPL.LineEdit.add_nested_key!(keymap, 'a', "foo")
REPL.LineEdit.add_nested_key!(keymap, 'a', "bar")

Which throws this error:

julia> REPL.LineEdit.add_nested_key!(keymap, 'a', "bar")
ERROR: MethodError: no method matching escape_string(::Char)
The function `escape_string` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  escape_string(::IO, ::Union{Base.AnnotatedString, SubString{<:Base.AnnotatedString}}, ::Any; keep, ascii, fullhex)
   @ Base strings/annotated_io.jl:266
  escape_string(::IO, ::Union{Base.AnnotatedString, SubString{<:Base.AnnotatedString}}; ...)
   @ Base strings/annotated_io.jl:266
  escape_string(::AbstractString, ::Any; keep, ascii, fullhex)
   @ Base strings/io.jl:467
  ...

Stacktrace:
 [1] add_nested_key!(keymap::Dict{Char, Any}, key::Union{Char, String}, value::Any; override::Bool)
   @ REPL.LineEdit ~/juliaup.depot/juliaup/julia-1.12.5+0.aarch64.apple.darwin14/Julia-1.12.app/Contents/Resources/julia/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:1785
 [2] add_nested_key!(keymap::Dict{Char, Any}, key::Union{Char, String}, value::Any)
   @ REPL.LineEdit ~/juliaup.depot/juliaup/julia-1.12.5+0.aarch64.apple.darwin14/Julia-1.12.app/Contents/Resources/julia/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:1779
 [3] top-level scope
   @ REPL[3]:1

But we want it to throw this instead:

ERROR: Conflicting definitions for keyseq a within one keymap

Detected by JET.

@DilumAluthge DilumAluthge marked this pull request as ready for review February 24, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant