mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Add support for most kinds of declarations to be declared and used as namespace members (#2575)
Support for global variables is still missing; they're a bit more tricky because they use a pattern to introduce their name. Prior to this change, explorer heavily relied on name comparisons to determine whether two declarations declare the same entity. Some of those instances are fixed in this PR, but more remain to be fixed, and some TODOs are added for some harder-to-fix instances.
This commit is contained in:
@@ -810,22 +810,22 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2,
|
||||
case Value::Kind::NominalClassType: {
|
||||
const auto& class1 = cast<NominalClassType>(*t1);
|
||||
const auto& class2 = cast<NominalClassType>(*t2);
|
||||
return class1.declaration().name() == class2.declaration().name() &&
|
||||
return DeclaresSameEntity(class1.declaration(), class2.declaration()) &&
|
||||
BindingMapEqual(class1.bindings().args(), class2.bindings().args(),
|
||||
equality_ctx);
|
||||
}
|
||||
case Value::Kind::InterfaceType: {
|
||||
const auto& iface1 = cast<InterfaceType>(*t1);
|
||||
const auto& iface2 = cast<InterfaceType>(*t2);
|
||||
return iface1.declaration().name() == iface2.declaration().name() &&
|
||||
return DeclaresSameEntity(iface1.declaration(), iface2.declaration()) &&
|
||||
BindingMapEqual(iface1.bindings().args(), iface2.bindings().args(),
|
||||
equality_ctx);
|
||||
}
|
||||
case Value::Kind::NamedConstraintType: {
|
||||
const auto& constraint1 = cast<NamedConstraintType>(*t1);
|
||||
const auto& constraint2 = cast<NamedConstraintType>(*t2);
|
||||
return constraint1.declaration().name() ==
|
||||
constraint2.declaration().name() &&
|
||||
return DeclaresSameEntity(constraint1.declaration(),
|
||||
constraint2.declaration()) &&
|
||||
BindingMapEqual(constraint1.bindings().args(),
|
||||
constraint2.bindings().args(), equality_ctx);
|
||||
}
|
||||
@@ -873,8 +873,13 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Value::Kind::ChoiceType:
|
||||
return cast<ChoiceType>(*t1).name() == cast<ChoiceType>(*t2).name();
|
||||
case Value::Kind::ChoiceType: {
|
||||
const auto& choice1 = cast<ChoiceType>(*t1);
|
||||
const auto& choice2 = cast<ChoiceType>(*t2);
|
||||
return DeclaresSameEntity(choice1.declaration(), choice2.declaration()) &&
|
||||
BindingMapEqual(choice1.type_args(), choice2.type_args(),
|
||||
equality_ctx);
|
||||
}
|
||||
case Value::Kind::TupleType:
|
||||
case Value::Kind::TupleValue: {
|
||||
const auto& tup1 = cast<TupleValueBase>(*t1);
|
||||
@@ -1023,7 +1028,7 @@ auto ValueStructurallyEqual(
|
||||
// The witness value is not part of determining value equality.
|
||||
const auto& assoc1 = cast<AssociatedConstant>(*v1);
|
||||
const auto& assoc2 = cast<AssociatedConstant>(*v2);
|
||||
return &assoc1.constant() == &assoc2.constant() &&
|
||||
return DeclaresSameEntity(assoc1.constant(), assoc2.constant()) &&
|
||||
TypeEqual(&assoc1.base(), &assoc2.base(), equality_ctx) &&
|
||||
TypeEqual(&assoc1.interface(), &assoc2.interface(), equality_ctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user