mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 10:52:38 +00: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:
10 files changed
+245
-10
No files matched your search
@@ -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