Support calling Carbon methods from C++ (#7078)

The FunctionDecl created for calling the Carbon thunk now takes a `self`
parameter for non-static methods, and the C++ thunk now passes an extra
argument for that `self` parameter when needed.

The CXXMethodDecl thunk created for calling methods now sets the storage
class appropriate depending on whether the method is static or not.

To reduce the number of parameters being passed around to thunk-building
functions, added a `FunctionInfo` struct and pass that around instead.
This commit is contained in:
Nicholas Bishop
2026-04-22 15:09:33 +00:00
committed by GitHub
parent b16cde9c53
commit 33d534ab31
3 changed files with 360 additions and 76 deletions
@@ -101,22 +101,13 @@ void G() {
}
''';
// --- fail_todo_method.carbon
// --- method.carbon
library "[[@TEST_NAME]]";
// CHECK:STDERR: fail_todo_method.carbon:[[@LINE+5]]:1: in import [InImport]
// CHECK:STDERR: other.carbon:11:3: error: semantics TODO: `unsupported: C++ calling a Carbon function with an implicit parameter` [SemanticsTodo]
// CHECK:STDERR: fn Method[self: Self]() { self; }
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
import Other;
import Cpp inline '''
void G() {
// CHECK:STDERR: fail_todo_method.carbon:[[@LINE+4]]:22: error: no member named 'Method' in 'Carbon::Other::C' [CppInteropParseError]
// CHECK:STDERR: 16 | Carbon::Other::C().Method();
// CHECK:STDERR: | ~~~~~~~~~~~~~~~~~~ ^
// CHECK:STDERR:
Carbon::Other::C().Method();
}
''';