mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user