|
|
@@ -218,15 +218,14 @@ static auto GetRequiredImplsFromConstraint(
|
|
|
const auto& facet_type_info =
|
|
|
context.facet_types().Get(facet_type_inst.facet_type_id);
|
|
|
|
|
|
- Diagnostics::ContextScope diagnostic_context(
|
|
|
- &context.emitter(), [&](auto& builder) {
|
|
|
+ auto identified_id = RequireIdentifiedFacetType(
|
|
|
+ context, loc_id, query_self_const_id, facet_type_inst,
|
|
|
+ [&](auto& builder) {
|
|
|
CARBON_DIAGNOSTIC(ImplLookupInUnidentifiedFacetType, Context,
|
|
|
"facet type {0} can not be identified", InstIdAsType);
|
|
|
builder.Context(loc_id, ImplLookupInUnidentifiedFacetType,
|
|
|
facet_type_inst_id);
|
|
|
});
|
|
|
- auto identified_id = RequireIdentifiedFacetType(
|
|
|
- context, loc_id, query_self_const_id, facet_type_inst);
|
|
|
if (!identified_id.has_value()) {
|
|
|
return std::nullopt;
|
|
|
}
|
|
|
@@ -347,22 +346,22 @@ static auto LookupImplWitnessInSelfFacetValue(
|
|
|
auto self_facet_value_const_id =
|
|
|
context.constant_values().Get(self_facet_value_inst_id);
|
|
|
|
|
|
- // TODO: Add a diagnostic context for when identification fails, instead of
|
|
|
- // CHECKing, such as for the type of Self inside a named constraint
|
|
|
- // definition.
|
|
|
- static_cast<void>(loc_id);
|
|
|
-
|
|
|
// The position of the interface in `required_impls()` is also the
|
|
|
// position of the witness for that interface in `FacetValue`. The
|
|
|
// `FacetValue` witnesses are the output of an impl lookup, which finds and
|
|
|
// returns witnesses in the same order.
|
|
|
auto identified_id = RequireIdentifiedFacetType(
|
|
|
- context, loc_id, self_facet_value_const_id, *facet_type);
|
|
|
- // This should not be possible as FacetValue is constructed by a conversion
|
|
|
- // to a facet type, which performs impl lookup for that facet type, and
|
|
|
- // lookup only succeeds for identified facet types.
|
|
|
- CARBON_CHECK(identified_id.has_value(),
|
|
|
- "FacetValue was constructed with an unidentified facet type");
|
|
|
+ context, loc_id, self_facet_value_const_id, *facet_type,
|
|
|
+ [&](auto& builder) {
|
|
|
+ CARBON_DIAGNOSTIC(ImplLookupInUnidentifiedFacetTypeOfQuerySelf, Context,
|
|
|
+ "facet type of value {0} can not be identified",
|
|
|
+ InstIdAsType);
|
|
|
+ builder.Context(loc_id, ImplLookupInUnidentifiedFacetTypeOfQuerySelf,
|
|
|
+ self_facet_value_inst_id);
|
|
|
+ });
|
|
|
+ if (!identified_id.has_value()) {
|
|
|
+ return EvalImplLookupResult::MakeNone();
|
|
|
+ }
|
|
|
auto facet_type_req_impls = llvm::enumerate(
|
|
|
context.identified_facet_types().Get(identified_id).required_impls());
|
|
|
auto it = llvm::find_if(facet_type_req_impls, [&](auto e) {
|