Don't create ErrorInst in Convert without producing a diagnostic (#6762)

While convert has the option to avoid diagnostics, when that flag is
false, ErrorInst results must also produce a diagnostic. Otherwise we
end up with errors in the semir but not error provided to the user.

The new diagnostics reveal that a number of tests for abstract types
were passing incorrectly. They had errors in the semir but no
diagnostics. A TODO is added in convert to allow an abstract conversion
target type when not initializing.
This commit is contained in:
Dana Jansens
2026-02-19 16:36:57 +00:00
committed by GitHub
parent 917a6ea971
commit 46fb941b3c
4 changed files with 231 additions and 72 deletions
+5 -1
View File
@@ -1741,6 +1741,10 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
// that `RequireConcreteType` returns true for facet types, since their
// representation is fixed. This allows us to support using the `Self` of an
// interface inside its definition.
//
// TODO: If `!target.is_initializer()` then we don't want to require the type
// to be concrete, only complete. But if we continue into Convert with an
// abstract type, we crash elsewhere.
if (!RequireConcreteType(
context, target.type_id, loc_id,
[&] {
@@ -1764,7 +1768,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
target.type_id);
},
[&] {
if (!target.diagnose || !target.is_initializer()) {
if (!target.diagnose) {
return context.emitter().BuildSuppressed();
}
CARBON_DIAGNOSTIC(AbstractTypeInInit, Error,