Skip to content

Commit

Permalink
[Parser] Allow parsing 'any' in structural position within enum assoc…
Browse files Browse the repository at this point in the history
…iated

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.
  • Loading branch information
hborla committed May 17, 2022
1 parent 6ac87ba commit 7a65b6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,7 @@ bool Parser::canParseTypeTupleBody() {

// If the tuple element starts with "ident :", then it is followed
// by a type annotation.
if (Tok.canBeArgumentLabel() &&
(peekToken().is(tok::colon) || peekToken().canBeArgumentLabel())) {
if (startsParameterName(/*isClosure=*/false)) {
consumeToken();
if (Tok.canBeArgumentLabel()) {
consumeToken();
Expand Down
9 changes: 9 additions & 0 deletions test/type/explicit_existential.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,12 @@ func testNestedMetatype() {
let _: (any (P.Type)).Type = (any P.Type).self
let _: ((any (P.Type))).Type = (any P.Type).self
}

func testEnumAssociatedValue() {
enum E {
case c1((any HasAssoc) -> Void)
// expected-error@+1 {{use of protocol 'HasAssoc' as a type must be written 'any HasAssoc'}}
case c2((HasAssoc) -> Void)
case c3((P) -> Void)
}
}

0 comments on commit 7a65b6b

Please sign in to comment.