Improve recovery from bad type imports. (#5953)

The main change here is that a bad type appearing somewhere within a
field or base class of a class shouldn't cause an import of that class
to fail. Instead, only that field or base class becomes inaccessible
from Carbon.

Also improve the way that type importing errors are diagnosed. While we
lose the precision of a diagnostic saying why a type is not supported,
we gain a useful source location for where the type was mentioned in C++
code.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2025-08-13 22:07:54 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 2140a57294
commit b2b0b4a73f
9 changed files with 165 additions and 146 deletions
+5 -8
View File
@@ -26,17 +26,14 @@ extern "C" int foo;
library "[[@TEST_NAME]]";
// CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
// CHECK:STDERR: ./extern_c_variable.h:2:16: error: semantics TODO: `Unsupported: Declaration type Var` [SemanticsTodo]
// CHECK:STDERR: extern "C" int foo;
// CHECK:STDERR: ^
import Cpp library "extern_c_variable.h";
fn MyF() -> i32 {
// CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+11]]:10: error: semantics TODO: `Unsupported: Declaration type Var` [SemanticsTodo]
// CHECK:STDERR: return Cpp.foo;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+8]]:10: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
// CHECK:STDERR: return Cpp.foo;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: error: member name `foo` not found in `Cpp` [MemberNameNotFoundInInstScope]
// CHECK:STDERR: fail_todo_import_extern_c_variable.carbon:[[@LINE+4]]:10: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
// CHECK:STDERR: return Cpp.foo;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR: