Skip to content

Commit 62a3fbf

Browse files
authored
Merge pull request #73480 from ahoppen/6.0/assertion-failure-completing-in-single-quote-string-literal
[Lexer] Fix an assertion failure when invoking code completion inside a single-quoted string literal
2 parents 94c988c + aa0e44c commit 62a3fbf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Parse/Lexer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,12 @@ void Lexer::diagnoseSingleQuoteStringLiteral(const char *TokStart,
18321832
OutputPtr = Ptr;
18331833
// Escape double quotes.
18341834
replacement.append("\\\"");
1835+
} else if (Ptr[-1] == 0) {
1836+
// The string literal might contain a null byte if the code completion
1837+
// position is inside the string literal. Don't include the null byte in
1838+
// the replacement string.
1839+
replacement.append(OutputPtr, Ptr - 1);
1840+
OutputPtr = Ptr;
18351841
}
18361842
}
18371843
assert(Ptr == TokEnd && Ptr[-1] == '\'');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fileprivate enum BundleComponent {
2+
// RUN: %sourcekitd-test -req=complete -pos=%(line + 1):25 %s -- %s
3+
case swiftVersions = 's'
4+
}

0 commit comments

Comments
 (0)