Skip to content

Commit a82f14b

Browse files
authored
Merge pull request #81265 from rintaro/parse-rdar149556573
[Parse] Parse operator function with value generics
2 parents d033eec + 682d263 commit a82f14b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8746,12 +8746,12 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
87468746
SourceLoc NameLoc;
87478747
if (Tok.isAnyOperator() || Tok.isAny(tok::exclaim_postfix, tok::amp_prefix)) {
87488748
// If the name is an operator token that ends in '<' and the following token
8749-
// is an identifier, split the '<' off as a separate token. This allows
8750-
// things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with generic type
8751-
// variable '<T>' as expected.
8749+
// is an identifier or 'let', split the '<' off as a separate token. This
8750+
// allows things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with
8751+
// generic type variable '<T>' as expected.
87528752
auto NameStr = Tok.getText();
87538753
if (NameStr.size() > 1 && NameStr.back() == '<' &&
8754-
peekToken().is(tok::identifier)) {
8754+
peekToken().isAny(tok::identifier, tok::kw_let)) {
87558755
NameStr = NameStr.slice(0, NameStr.size() - 1);
87568756
}
87578757
SimpleName = Context.getIdentifier(NameStr);

test/Sema/value_generics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func c<let M: Int>(with a: A<M>) {} // OK
5151
func d<T>(with a: A<T>) {} // expected-error {{cannot pass type 'T' as a value for generic value 'N'}}
5252
func e(with a: A<Int>) {} // expected-error {{cannot pass type 'Int' as a value for generic value 'N'}}
5353

54+
func *<let X: Int, let Y: Int>(l: A<X>, r: A<Y>) -> Int { l.int * r.int }
55+
5456
struct Generic<T: ~Copyable & ~Escapable> {}
5557
struct GenericWithIntParam<T: ~Copyable & ~Escapable, let N: Int> {}
5658

0 commit comments

Comments
 (0)