Add diagnostic support so that we can just pass in TypeId. (#3695)

Note we may also want to do this with NameId, maybe some other things,
but the TypeId use is pretty broad and repetitive -- I thought I'd start
with it first.
This commit is contained in:
Jon Ross-Perkins
2024-02-09 16:25:23 +00:00
committed by GitHub
parent bdff7ccf28
commit 1bf4dc53d9
16 changed files with 168 additions and 104 deletions
+9 -10
View File
@@ -70,12 +70,12 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
cast_type_id = context.AsCompleteType(cast_type_id, [&] {
CARBON_DIAGNOSTIC(IncompleteTypeInVarDecl, Error,
"{0} has incomplete type `{1}`.", llvm::StringLiteral,
std::string);
return context.emitter().Build(
type_node, IncompleteTypeInVarDecl,
enclosing_class_decl ? llvm::StringLiteral("Field")
: llvm::StringLiteral("Variable"),
context.sem_ir().StringifyType(cast_type_id));
SemIR::TypeId);
return context.emitter().Build(type_node, IncompleteTypeInVarDecl,
enclosing_class_decl
? llvm::StringLiteral("Field")
: llvm::StringLiteral("Variable"),
cast_type_id);
});
if (enclosing_class_decl) {
CARBON_CHECK(context_parse_node_kind ==
@@ -142,10 +142,9 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
cast_type_id = context.AsCompleteType(cast_type_id, [&] {
CARBON_DIAGNOSTIC(IncompleteTypeInLetDecl, Error,
"`let` binding has incomplete type `{0}`.",
std::string);
return context.emitter().Build(
type_node, IncompleteTypeInLetDecl,
context.sem_ir().StringifyType(cast_type_id));
SemIR::TypeId);
return context.emitter().Build(type_node, IncompleteTypeInLetDecl,
cast_type_id);
});
// Create the instruction, but don't add it to a block until after we've
// formed its initializer.