Unexpected behaviour in readLine?

Hello,

While writing a small console application I found this unexpected behaviour in readLine; it does not translate (or insert) the correct character for a suggestion. Instead, the returned String contains an unexpected character.

Try this small example (Xcode 11.5):

import Foundation
while true {
print(":> ", terminator:"")
let str = readLine(strippingNewline: false) ?? "#Empty#"
print(str)
}

In the debugging console (after the prompt ":>"), type:
(test

readLine will automatically insert the right parenthesis so that what's shown is
(test)

Now, move beyond the suggested right parenthesis with the right arrow key and press Enter.
The printed output is
(test?
with the question mark in a box.
I would have expected the right parenthesis to be returned even though it's an automated matching.

Is this intentional or is it a bug? Or is it some preference that I'm not aware of?

Best regards
/Patrik

When I tried this, the "question mark in a box" character in (test was U+F703 PRIVATE USE AREA-F703 (UTF-8: EF 9C 83).

I also tried: right arrow key, backspace/delete key, and Enter. The printed output (test� contained U+FFFD REPLACEMENT CHARACTER, so in that case the Swift.readLine API probably encountered some invalid UTF-8 bytes.

This is an issue with code completion in the Xcode 11.5 and 12.0 beta consoles. The closing parenthesis isn't inserted:

  • if you uncheck "Enable type-over completions" in the Xcode Preferences → Text Editing → Editing tab,

  • or if you change the Console option to "Use Terminal" in the scheme editor → Run → Options tab.

I suggest reporting an Xcode bug using the Feedback Assistant app or website.

1 Like

Thanks for the clarification that it's an issue with code completion.
I'll report it.
Cheers
/Patrik

1 Like