Implement 'alias' with transparent semantics. (#3701)

Adds `BindAlias` with a hybrid of `BindName` and `NameRef` semantics. I
think it's slightly closer to `BindName` because it introduces a name,
so I'm going more in that direction. This also matches the need for
`bind_name_id` with imports on enclosing scopes.

Note, only things that look like a name reference are being allowed on
the RHS of `alias`. This includes builtins that look like name
references, such as `bool`, but not ones that turn into values
underneath, such as `false`.
This commit is contained in:
Jon Ross-Perkins
2024-02-14 18:33:18 +00:00
committed by GitHub
parent 1974e44fd9
commit 1437b0e26d
40 changed files with 1312 additions and 92 deletions
@@ -110,6 +110,10 @@ static auto HandleBaseAsDecl(Context& context, Context::StateStackEntry state)
static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state,
bool saw_modifier) -> bool {
switch (context.PositionKind()) {
case Lex::TokenKind::Alias: {
ApplyIntroducer(context, state, NodeKind::AliasIntroducer, State::Alias);
return true;
}
case Lex::TokenKind::Base: {
HandleBaseAsDecl(context, state);
return true;
@@ -195,6 +199,7 @@ static auto ResolveAmbiguousTokenAsDeclaration(Context& context,
// also modifiers (such as `base`). Other introducer tokens need to be
// added by hand.
switch (context.PositionKind(Lookahead::NextToken)) {
case Lex::TokenKind::Alias:
case Lex::TokenKind::Class:
case Lex::TokenKind::Constraint:
case Lex::TokenKind::Fn: