Skip to content

Commit e6f5966

Browse files
authored
Merge pull request #81268 from rintaro/6.2-parse-rdar149556573
[6.2][Parse] Parse operator function with value generics
2 parents bb581a8 + bd6c04f commit e6f5966

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/Parse/ParseDecl.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -8737,12 +8737,12 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
87378737
SourceLoc NameLoc;
87388738
if (Tok.isAnyOperator() || Tok.isAny(tok::exclaim_postfix, tok::amp_prefix)) {
87398739
// If the name is an operator token that ends in '<' and the following token
8740-
// is an identifier, split the '<' off as a separate token. This allows
8741-
// things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with generic type
8742-
// variable '<T>' as expected.
8740+
// is an identifier or 'let', split the '<' off as a separate token. This
8741+
// allows things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with
8742+
// generic type variable '<T>' as expected.
87438743
auto NameStr = Tok.getText();
87448744
if (NameStr.size() > 1 && NameStr.back() == '<' &&
8745-
peekToken().is(tok::identifier)) {
8745+
peekToken().isAny(tok::identifier, tok::kw_let)) {
87468746
NameStr = NameStr.slice(0, NameStr.size() - 1);
87478747
}
87488748
SimpleName = Context.getIdentifier(NameStr);

test/Sema/value_generics.swift

+2
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)