Prevent ref self methods from being called from C++ with an rvalue (#7130)

If the Carbon method takes a `ref self`, give the C++ thunk an lvalue
ref-qualifier.
This commit is contained in:
Nicholas Bishop
2026-04-30 00:50:28 +00:00
committed by GitHub
parent f3f039516e
commit 2445ad9703
2 changed files with 37 additions and 21 deletions
@@ -68,7 +68,7 @@ void F() {
}
''';
// --- todo_ref_method_rvalue.carbon
// --- fail_ref_method_rvalue.carbon
library "[[@TEST_NAME]]";
import Cpp;
@@ -78,7 +78,13 @@ class C {
inline Cpp '''
void F() {
// TODO: this should be disallowed.
// CHECK:STDERR: fail_ref_method_rvalue.carbon:[[@LINE+7]]:3: error: 'this' argument to member function 'M' is an rvalue, but function has non-const lvalue ref-qualifier [CppInteropParseError]
// CHECK:STDERR: 17 | Carbon::C().M();
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_ref_method_rvalue.carbon:[[@LINE-8]]:25: note: 'M' declared here [CppInteropParseNote]
// CHECK:STDERR: 5 | fn M[ref self: Self]();
// CHECK:STDERR: | ^
// CHECK:STDERR:
Carbon::C().M();
}
''';