mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Set the value of .Self in a where to that of the outer .Self. (#2344)
Prior to this change, declarations like `let N:! X(.Self) where .(X(.Self).Y) == 5;` have the surprising behavior of the two `.Self` expressions resolving to two different symbolic values. Fix this by forcing the inner one to have the same symbolic value as the outer one, albeit with a different type.
This commit is contained in:
@@ -239,6 +239,14 @@ static auto ResolveNames(Expression& expression,
|
||||
auto& where = cast<WhereExpression>(expression);
|
||||
CARBON_RETURN_IF_ERROR(
|
||||
ResolveNames(where.self_binding().type(), enclosing_scope));
|
||||
// If we're already in a `.Self` context, remember it so that we can
|
||||
// reuse its value for the inner `.Self`.
|
||||
if (auto enclosing_dot_self =
|
||||
enclosing_scope.Resolve(".Self", where.source_loc());
|
||||
enclosing_dot_self.ok()) {
|
||||
where.set_enclosing_dot_self(
|
||||
&cast<GenericBinding>(enclosing_dot_self->base()));
|
||||
}
|
||||
// Introduce `.Self` into scope on the right of the `where` keyword.
|
||||
StaticScope where_scope;
|
||||
where_scope.AddParent(&enclosing_scope);
|
||||
|
||||
Reference in New Issue
Block a user