Skip to content

Commit 1f73669

Browse files
committed
error-in-import
1 parent c025f96 commit 1f73669

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

toolchain/check/eval.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ auto AddImportedConstant(Context& context, SemIR::Inst inst)
891891
inst.kind());
892892
Phase phase = GetPhase(context.constant_values(),
893893
context.types().GetConstantId(inst.type_id()));
894-
if (!ReplaceAllFieldsWithConstantValues(eval_context, &inst, &phase)) {
895-
return SemIR::ConstantId::NotConstant;
896-
}
894+
// We ignore the return value of ReplaceAllFieldsWithConstantValues and just
895+
// propagate runtime and error constant values into the resulting ConstantId.
896+
ReplaceAllFieldsWithConstantValues(eval_context, &inst, &phase);
897897
return MakeConstantResult(context, inst, phase);
898898
}
899899

@@ -2068,6 +2068,9 @@ auto TryEvalTypedInst<SemIR::WhereExpr>(EvalContext& eval_context,
20682068
inst_id)) {
20692069
if (IsPeriodSelf(eval_context,
20702070
eval_context.constant_values().Get(impls->lhs_id))) {
2071+
if (impls->rhs_id == SemIR::ErrorInst::InstId) {
2072+
return SemIR::ErrorInst::ConstantId;
2073+
}
20712074
if (impls->rhs_id == SemIR::TypeType::TypeInstId) {
20722075
// `.Self impls type` -> nothing to do.
20732076
} else if (auto facet_type =

toolchain/check/testdata/where_expr/constraints.carbon

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ fn NotEmptyStruct() {
125125
EmptyStruct(C);
126126
}
127127

128+
// --- fail_error_in_constraint.carbon
129+
130+
library "[[@TEST_NAME]]";
131+
132+
//@dump-sem-ir-begin
133+
// CHECK:STDERR: fail_error_in_constraint.carbon:[[@LINE+4]]:41: error: name `I` not found [NameNotFound]
134+
// CHECK:STDERR: fn WithError(U:! type where .Self impls I);
135+
// CHECK:STDERR: ^
136+
// CHECK:STDERR:
137+
fn WithError(U:! type where .Self impls I);
138+
//@dump-sem-ir-end
139+
140+
// --- import_error_in_constraint.carbon
141+
142+
library "[[@TEST_NAME]]";
143+
144+
import library "error_in_constraint";
145+
146+
fn F() {
147+
WithError(());
148+
}
149+
128150
// CHECK:STDOUT: --- state_constraints.carbon
129151
// CHECK:STDOUT:
130152
// CHECK:STDOUT: constants {
@@ -301,3 +323,36 @@ fn NotEmptyStruct() {
301323
// CHECK:STDOUT: %W.loc12_24.2 => constants.%W
302324
// CHECK:STDOUT: }
303325
// CHECK:STDOUT:
326+
// CHECK:STDOUT: --- fail_error_in_constraint.carbon
327+
// CHECK:STDOUT:
328+
// CHECK:STDOUT: constants {
329+
// CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic_self]
330+
// CHECK:STDOUT: %WithError.type: type = fn_type @WithError [concrete]
331+
// CHECK:STDOUT: %WithError: %WithError.type = struct_value () [concrete]
332+
// CHECK:STDOUT: }
333+
// CHECK:STDOUT:
334+
// CHECK:STDOUT: imports {
335+
// CHECK:STDOUT: }
336+
// CHECK:STDOUT:
337+
// CHECK:STDOUT: file {
338+
// CHECK:STDOUT: %WithError.decl: %WithError.type = fn_decl @WithError [concrete = constants.%WithError] {
339+
// CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [concrete]
340+
// CHECK:STDOUT: } {
341+
// CHECK:STDOUT: %.loc9_23.1: type = splice_block %.loc9_23.2 [concrete = <error>] {
342+
// CHECK:STDOUT: <elided>
343+
// CHECK:STDOUT: %.Self.ref: type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
344+
// CHECK:STDOUT: %I.ref: <error> = name_ref I, <error> [concrete = <error>]
345+
// CHECK:STDOUT: %.loc9_23.2: type = where_expr %.Self [concrete = <error>] {
346+
// CHECK:STDOUT: requirement_impls %.Self.ref, <error>
347+
// CHECK:STDOUT: }
348+
// CHECK:STDOUT: }
349+
// CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [concrete = <error>]
350+
// CHECK:STDOUT: }
351+
// CHECK:STDOUT: }
352+
// CHECK:STDOUT:
353+
// CHECK:STDOUT: generic fn @WithError(%U: <error>) {
354+
// CHECK:STDOUT: fn();
355+
// CHECK:STDOUT: }
356+
// CHECK:STDOUT:
357+
// CHECK:STDOUT: specific @WithError(<error>) {}
358+
// CHECK:STDOUT:

0 commit comments

Comments
 (0)