Skip to content

Commit 7a65b6b

Browse files
committed
[Parser] Allow parsing 'any' in structural position within enum associated
value types. This change simply calls into Parser::startsParameterName, which already supports parsing 'any' and 'some', instead of repeating the code without checking for contextual keywords.
1 parent 6ac87ba commit 7a65b6b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/Parse/ParseType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,8 +1643,7 @@ bool Parser::canParseTypeTupleBody() {
16431643

16441644
// If the tuple element starts with "ident :", then it is followed
16451645
// by a type annotation.
1646-
if (Tok.canBeArgumentLabel() &&
1647-
(peekToken().is(tok::colon) || peekToken().canBeArgumentLabel())) {
1646+
if (startsParameterName(/*isClosure=*/false)) {
16481647
consumeToken();
16491648
if (Tok.canBeArgumentLabel()) {
16501649
consumeToken();

test/type/explicit_existential.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,12 @@ func testNestedMetatype() {
320320
let _: (any (P.Type)).Type = (any P.Type).self
321321
let _: ((any (P.Type))).Type = (any P.Type).self
322322
}
323+
324+
func testEnumAssociatedValue() {
325+
enum E {
326+
case c1((any HasAssoc) -> Void)
327+
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}
328+
case c2((HasAssoc) -> Void)
329+
case c3((P) -> Void)
330+
}
331+
}

0 commit comments

Comments
 (0)