mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 17:11:04 +01:00
Support exporting class specifics to C++ (#7634)
This is similar to the previously-added support for accessing generic
carbon classes from C++, but with the specific defined by Carbon, rather
than being derived from template args supplied by clang in
`LoadExternalSpecializations`.
Example:
```carbon
class C(T: type) {
var t: T;
}
alias A = C(i32);
inline Cpp '''
void F() {
Carbon::A a;
a.t = 123;
}
'''
```
This commit is contained in:
@@ -81,7 +81,7 @@ library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp;
|
||||
|
||||
// CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:1: error: semantics TODO: `interop with specific class` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_todo_monomorphization_failure.carbon:[[@LINE+4]]:1: error: semantics TODO: `binding maps to a non-type template parameter` [SemanticsTodo]
|
||||
// CHECK:STDERR: class B(N: i32) {
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
|
||||
@@ -25,14 +25,10 @@ void F() {
|
||||
}
|
||||
''';
|
||||
|
||||
// --- fail_todo_specific_alias.carbon
|
||||
// --- specific_alias.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
import Cpp;
|
||||
|
||||
// CHECK:STDERR: fail_todo_specific_alias.carbon:[[@LINE+4]]:1: error: semantics TODO: `interop with specific class` [SemanticsTodo]
|
||||
// CHECK:STDERR: class C(T: type) {
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
class C(T: type) {
|
||||
var t: T;
|
||||
}
|
||||
@@ -40,20 +36,36 @@ alias A = C(i32);
|
||||
|
||||
inline Cpp '''
|
||||
void F() {
|
||||
// CHECK:STDERR: fail_todo_specific_alias.carbon:[[@LINE+8]]:11: error: semantics TODO: `interop with unsupported type` [SemanticsTodo]
|
||||
Carbon::A a;
|
||||
a.t = 123;
|
||||
}
|
||||
''';
|
||||
|
||||
// --- fail_unsupported_specific_arg.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
import Cpp;
|
||||
|
||||
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+4]]:1: error: semantics TODO: `failed to map specific type arg to C++` [SemanticsTodo]
|
||||
// CHECK:STDERR: class C(T: type) {
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
class C(T: type) {
|
||||
var t: T;
|
||||
}
|
||||
alias A = C(());
|
||||
|
||||
inline Cpp '''
|
||||
void F() {
|
||||
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+8]]:11: error: semantics TODO: `interop with unsupported type` [SemanticsTodo]
|
||||
// CHECK:STDERR: Carbon::A a;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_specific_alias.carbon:[[@LINE+4]]:11: error: no type named 'A' in namespace 'Carbon' [CppInteropParseError]
|
||||
// CHECK:STDERR: fail_unsupported_specific_arg.carbon:[[@LINE+4]]:11: error: no type named 'A' in namespace 'Carbon' [CppInteropParseError]
|
||||
// CHECK:STDERR: 23 | Carbon::A a;
|
||||
// CHECK:STDERR: | ~~~~~~~~^
|
||||
// CHECK:STDERR:
|
||||
Carbon::A a;
|
||||
// CHECK:STDERR: fail_todo_specific_alias.carbon:[[@LINE+4]]:3: error: use of undeclared identifier 'c' [CppInteropParseError]
|
||||
// CHECK:STDERR: 28 | c.t = 123;
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR:
|
||||
c.t = 123;
|
||||
a.t = 123;
|
||||
}
|
||||
''';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user