mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Use resolved names in typechecker (#974)
As a byproduct, replace NamedEntity with a type-erasing wrapper NamedEntityView, eliminate virtual inheritance from the AST, and eliminate interfaces from gen_rtti.
This commit is contained in:
@@ -543,19 +543,21 @@ auto TypeChecker::TypeCheckExp(Nonnull<Expression*> e, TypeEnv types,
|
||||
}
|
||||
case ExpressionKind::IdentifierExpression: {
|
||||
auto& ident = cast<IdentifierExpression>(*e);
|
||||
CHECK(ident.has_named_entity()) << "Identifier '" << *e << "' at "
|
||||
<< e->source_loc() << " was not resolved";
|
||||
std::optional<Nonnull<const Value*>> type = types.Get(ident.name());
|
||||
if (type) {
|
||||
SetStaticType(&ident, *type);
|
||||
// TODO: this should depend on what entity this name resolves to, but
|
||||
// we don't have access to that information yet.
|
||||
ident.set_value_category(Expression::ValueCategory::Var);
|
||||
return TCResult(types);
|
||||
} else {
|
||||
FATAL_COMPILATION_ERROR(e->source_loc())
|
||||
<< "could not find `" << ident.name() << "`";
|
||||
if (ident.named_entity().base().kind() ==
|
||||
AstNodeKind::FunctionDeclaration) {
|
||||
const auto& function =
|
||||
cast<FunctionDeclaration>(ident.named_entity().base());
|
||||
if (!function.has_static_type()) {
|
||||
CHECK(function.return_term().is_auto());
|
||||
FATAL_COMPILATION_ERROR(ident.source_loc())
|
||||
<< "Function calls itself, but has a deduced return type";
|
||||
}
|
||||
}
|
||||
SetStaticType(&ident, &ident.named_entity().static_type());
|
||||
// TODO: this should depend on what entity this name resolves to, but
|
||||
// we don't have access to that information yet.
|
||||
ident.set_value_category(Expression::ValueCategory::Var);
|
||||
return TCResult(types);
|
||||
}
|
||||
case ExpressionKind::IntLiteral:
|
||||
e->set_value_category(Expression::ValueCategory::Let);
|
||||
|
||||
Reference in New Issue
Block a user