Skip to content

Commit 886b647

Browse files
committed
fix <rdar://21712891> Swift Compiler bug: String subscripts with range should require closing bracket.
This is a parser bug causing us to accept invalid code.
1 parent 443af4a commit 886b647

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
615615
// If the lexer stopped with an EOF token whose spelling is ")", then this
616616
// is actually the tuple that is a string literal interpolation context.
617617
// Just accept the ")" and build the tuple as we usually do.
618-
if (Tok.is(tok::eof) && Tok.getText() == ")") {
618+
if (Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren) {
619619
RightLoc = Tok.getLoc();
620620
return Status;
621621
}

test/Parse/recovery.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,4 +710,10 @@ infix operator · { // expected-error {{'·' is considered to be an identifier,
710710
associativity none precedence 150
711711
}
712712

713+
// <rdar://problem/21712891> Swift Compiler bug: String subscripts with range should require closing bracket.
714+
func r21712891(s : String) -> String {
715+
let a = s.startIndex..<s.startIndex
716+
// The specific errors produced don't actually matter, but we need to reject this.
717+
return "\(s[a)" // expected-error 3 {{}}
718+
}
713719

0 commit comments

Comments
 (0)