Skip to content

Commit c254e9f

Browse files
authored
C++ interop: Correctly report the unsupported param type when using explicit object param (#6179)
This fixes a bug, which seems to have been introduced in #6108. In the new test, without this change, we will diagnose with ``` error: semantics TODO: `Unsupported: parameter type: ExplicitObjectParam` [SemanticsTodo] ```
1 parent fd74e49 commit c254e9f

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

toolchain/check/cpp/import.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,14 +1365,13 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id,
13651365
clang_decl.getType()->castAs<clang::FunctionProtoType>();
13661366
for (int i : llvm::seq(num_params)) {
13671367
const auto* param = clang_decl.getNonObjectParameter(i);
1368+
clang::QualType orig_param_type = function_type->getParamType(
1369+
clang_decl.hasCXXExplicitFunctionObjectParameter() + i);
1370+
13681371
// The parameter type is decayed but hasn't necessarily had its qualifiers
13691372
// removed.
13701373
// TODO: The presence of qualifiers here is probably a Clang bug.
1371-
clang::QualType param_type =
1372-
function_type
1373-
->getParamType(clang_decl.hasCXXExplicitFunctionObjectParameter() +
1374-
i)
1375-
.getUnqualifiedType();
1374+
clang::QualType param_type = orig_param_type.getUnqualifiedType();
13761375

13771376
// We map `T&` parameters to `addr param: T*`, and `T&&` parameters to
13781377
// `param: T`.
@@ -1391,9 +1390,8 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id,
13911390
EndSubpatternAsExpr(context, orig_type_inst_id);
13921391

13931392
if (!type_id.has_value()) {
1394-
context.TODO(loc_id,
1395-
llvm::formatv("Unsupported: parameter type: {0}",
1396-
function_type->getParamType(i).getAsString()));
1393+
context.TODO(loc_id, llvm::formatv("Unsupported: parameter type: {0}",
1394+
orig_param_type.getAsString()));
13971395
return SemIR::InstBlockId::None;
13981396
}
13991397

toolchain/check/testdata/interop/cpp/class/method.carbon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) {
176176
//@dump-sem-ir-end
177177
}
178178

179+
// --- fail_call_explicit_object_param_with_unsupported_type_param.carbon
180+
181+
library "[[@TEST_NAME]]";
182+
183+
import Cpp inline '''
184+
struct ExplicitObjectParam {
185+
void F(this ExplicitObjectParam, _BitInt(23) x);
186+
};
187+
''';
188+
189+
fn Call(e: Cpp.ExplicitObjectParam) {
190+
// CHECK:STDERR: fail_call_explicit_object_param_with_unsupported_type_param.carbon:[[@LINE+4]]:3: error: semantics TODO: `Unsupported: parameter type: _BitInt(23)` [SemanticsTodo]
191+
// CHECK:STDERR: e.(Cpp.ExplicitObjectParam.F)(1);
192+
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193+
// CHECK:STDERR:
194+
e.(Cpp.ExplicitObjectParam.F)(1);
195+
}
196+
179197
// --- explicit_object_param_overloaded.h
180198

181199
struct Another {

0 commit comments

Comments
 (0)