1919
2020namespace Carbon ::Check {
2121
22+ namespace {
23+ // Entity kinds for the diagnostic. Converted to an int for a select.
24+ enum class EntityKind : uint8_t {
25+ Function,
26+ GenericClass,
27+ GenericInterface,
28+ };
29+ } // namespace
30+
2231// Resolves the callee expression in a call to a specific callee, or diagnoses
2332// if no specific callee can be identified. This verifies the arity of the
2433// callee and determines any compile-time arguments, but doesn't check that the
@@ -31,7 +40,7 @@ namespace Carbon::Check {
3140// callee is not generic, or `nullopt` if an error has been diagnosed.
3241static auto ResolveCalleeInCall (Context& context, SemIR::LocId loc_id,
3342 const SemIR::EntityWithParamsBase& entity,
34- llvm::StringLiteral entity_kind_for_diagnostic,
43+ EntityKind entity_kind_for_diagnostic,
3544 SemIR::GenericId entity_generic_id,
3645 SemIR::SpecificId enclosing_specific_id,
3746 SemIR::InstId self_id,
@@ -43,16 +52,20 @@ static auto ResolveCalleeInCall(Context& context, SemIR::LocId loc_id,
4352 auto params = context.inst_blocks ().GetOrEmpty (callee_info.param_refs_id );
4453 if (arg_ids.size () != params.size ()) {
4554 CARBON_DIAGNOSTIC (CallArgCountMismatch, Error,
46- " {0} argument{0:s} passed to {1} expecting "
47- " {2} argument{2:s}" ,
48- IntAsSelect, llvm::StringLiteral, IntAsSelect);
49- CARBON_DIAGNOSTIC (InCallToEntity, Note, " calling {0} declared here" ,
50- llvm::StringLiteral);
55+ " {0} argument{0:s} passed to "
56+ " {1:=0:function|=1:generic class|=2:generic interface}"
57+ " expecting {2} argument{2:s}" ,
58+ IntAsSelect, IntAsSelect, IntAsSelect);
59+ CARBON_DIAGNOSTIC (
60+ InCallToEntity, Note,
61+ " calling {0:=0:function|=1:generic class|=2:generic interface}"
62+ " declared here" ,
63+ IntAsSelect);
5164 context.emitter ()
5265 .Build (loc_id, CallArgCountMismatch, arg_ids.size (),
53- entity_kind_for_diagnostic, params.size ())
66+ static_cast < int >( entity_kind_for_diagnostic) , params.size ())
5467 .Note (callee_info.callee_loc , InCallToEntity,
55- entity_kind_for_diagnostic)
68+ static_cast < int >( entity_kind_for_diagnostic) )
5669 .Emit ();
5770 return std::nullopt ;
5871 }
@@ -80,8 +93,9 @@ static auto PerformCallToGenericClass(Context& context, SemIR::LocId loc_id,
8093 -> SemIR::InstId {
8194 const auto & generic_class = context.classes ().Get (class_id);
8295 auto callee_specific_id = ResolveCalleeInCall (
83- context, loc_id, generic_class, " generic class" , generic_class.generic_id ,
84- enclosing_specific_id, /* self_id=*/ SemIR::InstId::Invalid, arg_ids);
96+ context, loc_id, generic_class, EntityKind::GenericClass,
97+ generic_class.generic_id , enclosing_specific_id,
98+ /* self_id=*/ SemIR::InstId::Invalid, arg_ids);
8599 if (!callee_specific_id) {
86100 return SemIR::InstId::BuiltinError;
87101 }
@@ -99,8 +113,9 @@ static auto PerformCallToGenericInterface(
99113 llvm::ArrayRef<SemIR::InstId> arg_ids) -> SemIR::InstId {
100114 const auto & interface = context.interfaces ().Get (interface_id);
101115 auto callee_specific_id = ResolveCalleeInCall (
102- context, loc_id, interface, " generic interface" , interface.generic_id ,
103- enclosing_specific_id, /* self_id=*/ SemIR::InstId::Invalid, arg_ids);
116+ context, loc_id, interface, EntityKind::GenericInterface,
117+ interface.generic_id , enclosing_specific_id,
118+ /* self_id=*/ SemIR::InstId::Invalid, arg_ids);
104119 if (!callee_specific_id) {
105120 return SemIR::InstId::BuiltinError;
106121 }
@@ -143,7 +158,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
143158 // If the callee is a generic function, determine the generic argument values
144159 // for the call.
145160 auto callee_specific_id = ResolveCalleeInCall (
146- context, loc_id, callable, " function " , callable.generic_id ,
161+ context, loc_id, callable, EntityKind::Function , callable.generic_id ,
147162 callee_function.enclosing_specific_id , callee_function.self_id , arg_ids);
148163 if (!callee_specific_id) {
149164 return SemIR::InstId::BuiltinError;
0 commit comments