Skip to content

Commit

Permalink
Fix for a crash caused by choice alternative name being the same as c…
Browse files Browse the repository at this point in the history
…hoice name (#1243)

Fixes #1248

Changed resolve names logic to add choice name to name resolution after choice's alternatives are added.
  • Loading branch information
pk19604014 authored May 11, 2022
1 parent 8c28000 commit e06d67a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
compilation_unit {
declarations {
choice {
alternatives {
signature {
primitive_operator {
arguments {
intrinsic {
argument {
fields {
primitive_operator {
arguments {
identifier {
}
}
}
}
}
}
}
}
}
}
}
}
}
5 changes: 3 additions & 2 deletions explorer/interpreter/resolve_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static auto AddExposedNames(const Declaration& declaration,
break;
}
case DeclarationKind::ChoiceDeclaration: {
auto& choice = cast<ChoiceDeclaration>(declaration);
CARBON_RETURN_IF_ERROR(enclosing_scope.Add(choice.name(), &choice));
// Choice name is added to the scope after the choice's alternatives.
// See https://github.com/carbon-language/carbon-lang/issues/1248.
break;
}
case DeclarationKind::VariableDeclaration: {
Expand Down Expand Up @@ -424,6 +424,7 @@ static auto ResolveNames(Declaration& declaration, StaticScope& enclosing_scope)
<< "` in choice type";
}
}
CARBON_RETURN_IF_ERROR(enclosing_scope.Add(choice.name(), &choice));
break;
}
case DeclarationKind::VariableDeclaration: {
Expand Down

0 comments on commit e06d67a

Please sign in to comment.