mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 09:51:04 +01:00
Support for functions with a self parameter. (#3338)
So far, such functions can only be defined; calls are not supported yet.
This commit is contained in:
@@ -51,17 +51,17 @@ static auto HandlePattern(Context& context, Context::PatternKind pattern_kind)
|
||||
context.PushState(state);
|
||||
};
|
||||
|
||||
// The first item should be an identifier or, in an implicit parameter list,
|
||||
// `self`.
|
||||
// The first item should be an identifier or `self`.
|
||||
bool has_name = false;
|
||||
if (auto identifier = context.ConsumeIf(Lex::TokenKind::Identifier)) {
|
||||
context.AddLeafNode(NodeKind::Name, *identifier);
|
||||
has_name = true;
|
||||
} else if (pattern_kind == Context::PatternKind::ImplicitParameter) {
|
||||
if (auto self = context.ConsumeIf(Lex::TokenKind::SelfValueIdentifier)) {
|
||||
context.AddLeafNode(NodeKind::SelfValueName, *self);
|
||||
has_name = true;
|
||||
}
|
||||
} else if (auto self =
|
||||
context.ConsumeIf(Lex::TokenKind::SelfValueIdentifier)) {
|
||||
// Checking will validate the `self` is only declared in the implicit
|
||||
// parameter list of a function.
|
||||
context.AddLeafNode(NodeKind::SelfValueName, *self);
|
||||
has_name = true;
|
||||
}
|
||||
if (!has_name) {
|
||||
// Add a placeholder for the name.
|
||||
|
||||
Reference in New Issue
Block a user