mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:42:01 +01:00
Explorer: Support class subtyping (#2460)
Features: * Adds support for [subtyping](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/classes.md#subtyping) for local variables, and function parameters Changes: * Update function parameter `Deduce` to handle subtyping * Update `InstantiateType` to support `PointerType` * Update `Convert` to support convertion from child class to a base class Relates to #1881 Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
Geoff Romer
parent
8e6d48004b
commit
9299e51511
@@ -1183,4 +1183,20 @@ void ImplBinding::PrintID(llvm::raw_ostream& out) const {
|
||||
out << *type_var_ << " as " << **iface_;
|
||||
}
|
||||
|
||||
auto NominalClassType::InheritsClass(Nonnull<const Value*> other) const
|
||||
-> bool {
|
||||
const auto* other_class = dyn_cast<NominalClassType>(other);
|
||||
if (!other_class) {
|
||||
return false;
|
||||
}
|
||||
std::optional<Nonnull<const NominalClassType*>> ancestor_class = this;
|
||||
while (ancestor_class) {
|
||||
if (TypeEqual(*ancestor_class, other_class, std::nullopt)) {
|
||||
return true;
|
||||
}
|
||||
ancestor_class = (*ancestor_class)->base();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user