mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Explorer: move subtyping logic to TypeChecker (#2484)
Addresses comments from this discussion: https://github.com/carbon-language/carbon-lang/pull/2460#discussion_r1046444433 Features: * Move subtyping logic from Interpreter to TypeChecker, exposing subtyping as a series of access to `.base`. * Excludes function parameter conversion, which is still done in ::Convert due to parameters conversion being handled differently. Changes: * Add new `class BaseAccessExpression : public MemberAccessExpression`, allowing rewrites * Handle `BaseAccessExpression` expression type in Interpreter * Move subtyping logic to `TypeChecker::ImplicitlyConvert`
This commit is contained in:
@@ -199,10 +199,16 @@ static auto GetElement(Nonnull<Arena*> arena, Nonnull<const Value*> v,
|
||||
}
|
||||
}
|
||||
case ElementKind::BaseElement:
|
||||
if (const auto* class_value = dyn_cast<NominalClassValue>(v)) {
|
||||
return GetBaseElement(class_value, source_loc);
|
||||
} else {
|
||||
CARBON_FATAL() << "Invalid value for base element";
|
||||
switch (v->kind()) {
|
||||
case Value::Kind::NominalClassValue:
|
||||
return GetBaseElement(cast<NominalClassValue>(v), source_loc);
|
||||
case Value::Kind::PointerValue: {
|
||||
const auto* ptr = cast<PointerValue>(v);
|
||||
return arena->New<PointerValue>(
|
||||
ptr->address().ElementAddress(path_comp.element()));
|
||||
}
|
||||
default:
|
||||
CARBON_FATAL() << "Invalid value for base element";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user