diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index 1dac96dbac21..a9389ed19561 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -447,6 +447,9 @@ class ImportRefResolver : public ImportContext { // Step 1: check for a constant value. auto existing = FindResolvedConstId(work.inst_id); + if (existing.const_id == SemIR::ErrorInst::ConstantId) { + return existing.const_id; + } if (existing.const_id.has_value() && !work.retry_with_constant_value) { work_stack_.pop_back(); continue; @@ -583,6 +586,11 @@ class ImportRefResolver : public ImportContext { return result; } auto ir_inst = cursor_ir->import_ir_insts().Get(import_ir_inst_id); + if (ir_inst.ir_id() == SemIR::ImportIRId::Cpp) { + local_context().TODO(SemIR::LocId::None, + "Unsupported: Importing C++ indirectly"); + return {.const_id = SemIR::ErrorInst::ConstantId}; + } const auto* prev_ir = cursor_ir; auto prev_inst_id = cursor_inst_id; diff --git a/toolchain/check/testdata/interop/cpp/import.carbon b/toolchain/check/testdata/interop/cpp/import.carbon index 4ef1a0b94f0e..c1efa9df01b9 100644 --- a/toolchain/check/testdata/interop/cpp/import.carbon +++ b/toolchain/check/testdata/interop/cpp/import.carbon @@ -46,6 +46,37 @@ fn F() { //@dump-sem-ir-end } +// ============================================================================ +// Import C++ struct indirectly +// ============================================================================ + +// --- struct.h + +struct MyStruct { void Foo(); }; + +// --- struct_api.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "struct.h"; + +alias MyStructAlias = Cpp.MyStruct; + +// --- fail_todo_import_struct_api.carbon +// CHECK:STDERR: fail_todo_import_struct_api.carbon: error: semantics TODO: `Unsupported: Importing C++ indirectly` [SemanticsTodo] +// CHECK:STDERR: + +library "[[@TEST_NAME]]"; + +import library "struct_api"; + +fn F() { + //@dump-sem-ir-begin + var x: MyStructAlias; + x.Foo(); + //@dump-sem-ir-end +} + // ============================================================================ // Import C++ function indirectly // ============================================================================ @@ -101,6 +132,29 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: --- fail_todo_import_struct_api.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Main.MyStructAlias: type = import_ref Main//struct_api, MyStructAlias, loaded [concrete = ] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %x.patt: = binding_pattern x [concrete] +// CHECK:STDOUT: %x.var_patt: = var_pattern %x.patt [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: %x.var: ref = var %x.var_patt [concrete = ] +// CHECK:STDOUT: %MyStructAlias.ref: type = name_ref MyStructAlias, imports.%Main.MyStructAlias [concrete = ] +// CHECK:STDOUT: %x: = bind_name x, [concrete = ] +// CHECK:STDOUT: %x.ref: = name_ref x, %x [concrete = ] +// CHECK:STDOUT: %Foo.ref: = name_ref Foo, [concrete = ] +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: --- fail_todo_import_function_api.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants {