Xcode 14.2 editor mis-parses Swift extended delimiter string with backslash at end

This post describes an error in the parsing of extended delimiter strings in the Xcode 14.2 Swift editor, but not in the compiler. The problem occurs with an extended delimiter string with a backslash at the end: #"xyzzy\"#. The editor treats the backslash as escaping the closing quote mark, and thus sees the string as unclosed. The bug is manifested in the syntax coloring of text following the string on the same line, and also in the indentation of subsequent lines if there were opening or closing parentheses or braces following the string on the same line.

Here is a trivial command-line app main.swift that illustrates the bug.

print("Hello, World!")
print(#"Hello, World!\ "#)
print(#"Hello, World!\"#)
print("I'm not dead yet")

This screen shot shows the editor misbehavior:

Note that the color of the closing parenthesis on line 3 shows that the editor thinks it is part of the string, and that the indentation of line 4 shows that the editor did not recognize the closing parenthesis on line 3.

The execution output shows that the bug is limited to the editor — the program compiled and ran correctly:

what is the question here? You can file bugs using Feedback Assistant.

Xcode 14.2 editor mis-parses Swift extended delimiter string with backslash at end
 
 
Q