mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:44:46 +01:00
Avoid crashing when importing a C++ struct indirectly (#6086)
Return an error constant id instead and output a TODO. Part of #6060.
This commit is contained in:
@@ -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: <elided>
|
||||
// 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 = <error>]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %x.patt: <error> = binding_pattern x [concrete]
|
||||
// CHECK:STDOUT: %x.var_patt: <error> = var_pattern %x.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %x.var: ref <error> = var %x.var_patt [concrete = <error>]
|
||||
// CHECK:STDOUT: %MyStructAlias.ref: type = name_ref MyStructAlias, imports.%Main.MyStructAlias [concrete = <error>]
|
||||
// CHECK:STDOUT: %x: <error> = bind_name x, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %x.ref: <error> = name_ref x, %x [concrete = <error>]
|
||||
// CHECK:STDOUT: %Foo.ref: <error> = name_ref Foo, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_todo_import_function_api.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
|
||||
Reference in New Issue
Block a user