mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 09:31:05 +01:00
Add initial support for exporting generic classes (#7595)
Currently only fields of generic classes are exported; methods of
generic classes are not supported yet.
Simple example:
```carbon
class C(T: type) {
var t: T;
}
inline Cpp '''
void F() {
Carbon::C<int> c;
c.t = 123;
Carbon::C<float> c2;
c2.t = 124.5;
}
''';
```
This commit is contained in:
@@ -149,6 +149,10 @@ library "[[@TEST_NAME]]";
|
||||
import Cpp;
|
||||
|
||||
class GenericClass(T: type) {
|
||||
// CHECK:STDERR: fail_todo_call_generic_class_constructor.carbon:[[@LINE+4]]:3: error: semantics TODO: `non-class non-namespace name scope` [SemanticsTodo]
|
||||
// CHECK:STDERR: fn GenericClass(_: T) -> Self {
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn GenericClass(_: T) -> Self {
|
||||
return {};
|
||||
}
|
||||
@@ -156,17 +160,12 @@ class GenericClass(T: type) {
|
||||
|
||||
inline Cpp '''
|
||||
void f() {
|
||||
// CHECK:STDERR: fail_todo_call_generic_class_constructor.carbon:[[@LINE+12]]:11: error: no member named 'GenericClass' in namespace 'Carbon' [CppInteropParseError]
|
||||
// CHECK:STDERR: 25 | Carbon::GenericClass<int> c(0);
|
||||
// CHECK:STDERR: | ^~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_call_generic_class_constructor.carbon:[[@LINE+8]]:27: error: expected '(' for function-style cast or type construction [CppInteropParseError]
|
||||
// CHECK:STDERR: 25 | Carbon::GenericClass<int> c(0);
|
||||
// CHECK:STDERR: | ~~~^
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_call_generic_class_constructor.carbon:[[@LINE+4]]:29: error: use of undeclared identifier 'c' [CppInteropParseError]
|
||||
// CHECK:STDERR: 25 | Carbon::GenericClass<int> c(0);
|
||||
// CHECK:STDERR: | ^
|
||||
// CHECK:STDERR: fail_todo_call_generic_class_constructor.carbon:[[@LINE+7]]:29: error: no matching constructor for initialization of 'Carbon::GenericClass<int>' [CppInteropParseError]
|
||||
// CHECK:STDERR: 24 | Carbon::GenericClass<int> c(0);
|
||||
// CHECK:STDERR: | ^ ~
|
||||
// CHECK:STDERR: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const GenericClass<int>' for 1st argument [CppInteropParseNote]
|
||||
// CHECK:STDERR: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'GenericClass<int>' for 1st argument [CppInteropParseNote]
|
||||
// CHECK:STDERR: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided [CppInteropParseNote]
|
||||
// CHECK:STDERR:
|
||||
Carbon::GenericClass<int> c(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user