Skip to content

[6.2][Parse] Parse operator function with value generics #81268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8737,12 +8737,12 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
SourceLoc NameLoc;
if (Tok.isAnyOperator() || Tok.isAny(tok::exclaim_postfix, tok::amp_prefix)) {
// If the name is an operator token that ends in '<' and the following token
// is an identifier, split the '<' off as a separate token. This allows
// things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with generic type
// variable '<T>' as expected.
// is an identifier or 'let', split the '<' off as a separate token. This
// allows things like 'func ==<T>(x:T, y:T) {}' to parse as '==' with
// generic type variable '<T>' as expected.
auto NameStr = Tok.getText();
if (NameStr.size() > 1 && NameStr.back() == '<' &&
peekToken().is(tok::identifier)) {
peekToken().isAny(tok::identifier, tok::kw_let)) {
NameStr = NameStr.slice(0, NameStr.size() - 1);
}
SimpleName = Context.getIdentifier(NameStr);
Expand Down
2 changes: 2 additions & 0 deletions test/Sema/value_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func c<let M: Int>(with a: A<M>) {} // OK
func d<T>(with a: A<T>) {} // expected-error {{cannot pass type 'T' as a value for generic value 'N'}}
func e(with a: A<Int>) {} // expected-error {{cannot pass type 'Int' as a value for generic value 'N'}}

func *<let X: Int, let Y: Int>(l: A<X>, r: A<Y>) -> Int { l.int * r.int }

struct Generic<T: ~Copyable & ~Escapable> {}
struct GenericWithIntParam<T: ~Copyable & ~Escapable, let N: Int> {}

Expand Down