Skip to content

Commit 09d884d

Browse files
authored
---
yaml --- r: 278510 b: refs/heads/swift-5.1-old-llvm-branch c: 003850f h: refs/heads/master
1 parent 3f04660 commit 09d884d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-01-24-a: b6f62823aa5010b2ae53f15f72a57
12411241
refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e0
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
1244-
refs/heads/swift-5.1-old-llvm-branch: 7b0d10e2c762c5e3d4fb1ca1bef969db8a1cc536
1244+
refs/heads/swift-5.1-old-llvm-branch: 003850fb0d886493305f7f7a0b23dbadc2bbfd07
12451245
refs/heads/swift-5.1-branch: 8060872acb4105d9655e020fe047e1ebcd77d0fb
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e

branches/swift-5.1-old-llvm-branch/lib/Parse/ParseStmt.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ bool Parser::isStartOfStmt() {
9292
// putting a label on something inappropriate in parseStmt().
9393
return isStartOfStmt();
9494
}
95+
96+
case tok::at_sign: {
97+
// Might be a statement or case attribute. The only one of these we have
98+
// right now is `@unknown default`, so hardcode a check for an attribute
99+
// without any parens.
100+
if (!peekToken().is(tok::identifier))
101+
return false;
102+
Parser::BacktrackingScope backtrack(*this);
103+
consumeToken(tok::at_sign);
104+
consumeToken(tok::identifier);
105+
return isStartOfStmt();
106+
}
95107
}
96108
}
97109

branches/swift-5.1-old-llvm-branch/test/Parse/switch.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,38 @@ switch x {
609609
@unknown default: // expected-error {{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
610610
break
611611
}
612+
613+
func testReturnBeforeUnknownDefault() {
614+
switch x { // expected-error {{switch must be exhaustive}}
615+
case 1:
616+
return
617+
@unknown default: // expected-note {{remove '@unknown' to handle remaining values}}
618+
break
619+
}
620+
}
621+
622+
func testReturnBeforeIncompleteUnknownDefault() {
623+
switch x { // expected-error {{switch must be exhaustive}}
624+
case 1:
625+
return
626+
@unknown default // expected-error {{expected ':' after 'default'}}
627+
// expected-note@-1 {{remove '@unknown' to handle remaining values}}
628+
}
629+
}
630+
631+
func testReturnBeforeIncompleteUnknownDefault2() {
632+
switch x { // expected-error {{switch must be exhaustive}} expected-note {{do you want to add a default clause?}}
633+
case 1:
634+
return
635+
@unknown // expected-error {{unknown attribute 'unknown'}}
636+
} // expected-error {{expected declaration}}
637+
}
638+
639+
func testIncompleteArrayLiteral() {
640+
switch x { // expected-error {{switch must be exhaustive}}
641+
case 1:
642+
_ = [1 // expected-error {{expected ']' in container literal expression}} expected-note {{to match this opening '['}}
643+
@unknown default: // expected-note {{remove '@unknown' to handle remaining values}}
644+
()
645+
}
646+
}

0 commit comments

Comments
 (0)