mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Reverse interop support for type aliases. (#7043)
Allow any type that has a mapping from Carbon to C++ to be exposed to C++ via name lookup. This also exposes the logic to export Carbon classes to C++ to apply during type mapping, which gives very slight support for passing Carbon types to C++ functions from Carbon, but not really enough to sensibly test yet. Depends on #7042.
This commit is contained in:
@@ -316,9 +316,13 @@ class Derived {
|
||||
fn F[self: Self]() {
|
||||
//@dump-sem-ir-begin
|
||||
// TODO: It should be possible to call protected methods in the base class.
|
||||
// CHECK:STDERR: fail_todo_import_function_member_protected_extend_call_instance_in_member.carbon:[[@LINE+4]]:5: error: call argument of type `Derived` is not supported [CppCallArgTypeNotSupported]
|
||||
// CHECK:STDERR: self.instance_fn();
|
||||
// CHECK:STDERR: ^~~~
|
||||
// CHECK:STDERR: fail_todo_import_function_member_protected_extend_call_instance_in_member.carbon:[[@LINE+8]]:22: error: no matching function for call to 'instance_fn' [CppInteropParseError]
|
||||
// CHECK:STDERR: 19 | self.instance_fn();
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: fail_todo_import_function_member_protected_extend_call_instance_in_member.carbon:[[@LINE-10]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./function_member_protected.h:4:8: note: candidate function not viable: cannot convert argument of incomplete type 'const Carbon::Derived' to 'C' for object argument [CppInteropParseNote]
|
||||
// CHECK:STDERR: 4 | auto instance_fn() -> void;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
self.instance_fn();
|
||||
//@dump-sem-ir-end
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/type_alias/export.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/type_alias/export.carbon
|
||||
|
||||
// --- aliases.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
alias A = i32;
|
||||
|
||||
class C {}
|
||||
alias CA = C;
|
||||
|
||||
inline Cpp '''
|
||||
// Valid redeclarations -- same type.
|
||||
using T = Carbon::A;
|
||||
using T = int;
|
||||
|
||||
// Valid redeclarations -- same type.
|
||||
using U = Carbon::C;
|
||||
using U = Carbon::CA;
|
||||
''';
|
||||
|
||||
// Valid: Cpp.U is the same type as CA.
|
||||
fn F(p: CA*) -> Cpp.U* {
|
||||
return p;
|
||||
}
|
||||
+2
-2
@@ -6,9 +6,9 @@
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/typedef.carbon
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/type_alias/import.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/typedef.carbon
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/type_alias/import.carbon
|
||||
|
||||
// --- i32_typedef.h
|
||||
|
||||
Reference in New Issue
Block a user