Skip to content

Commit 507f82c

Browse files
authored
Merge pull request #82717 from Xazax-hun/instantiation-fail-error-location
[cxx-interop] Add source location to instantiation error
2 parents 677b897 + 15a6cca commit 507f82c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7103,8 +7103,9 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
71037103
// TODO: Use the location of the apply here.
71047104
// TODO: This error message should not reference implementation details.
71057105
// See: https://github.com/apple/swift/pull/33053#discussion_r477003350
7106-
ctx.Diags.diagnose(SourceLoc(), diag::unable_to_convert_generic_swift_types,
7107-
getFuncName(), failedTypesStr);
7106+
Impl.diagnose(HeaderLoc(func->getBeginLoc()),
7107+
diag::unable_to_convert_generic_swift_types, getFuncName(),
7108+
failedTypesStr);
71087109
return nullptr;
71097110
}
71107111

@@ -7123,9 +7124,9 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
71237124
templateParamsStream,
71247125
/*IncludeType*/ true);
71257126
});
7126-
ctx.Diags.diagnose(SourceLoc(),
7127-
diag::unable_to_substitute_cxx_function_template,
7128-
getFuncName(), templateParams);
7127+
Impl.diagnose(HeaderLoc(func->getBeginLoc()),
7128+
diag::unable_to_substitute_cxx_function_template,
7129+
getFuncName(), templateParams);
71297130
return nullptr;
71307131
}
71317132
sema.InstantiateFunctionDefinition(clang::SourceLocation(), spec);

test/Interop/Cxx/templates/function-template-typechecker-errors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public protocol A { }
2525
public protocol B { }
2626
public protocol C { }
2727

28-
// CHECK: error: unexpected error produced: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'passThrough' could not be converted: any A & B
28+
// CHECK: function-templates.h{{.*}}: error: diagnostic produced elsewhere: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'passThrough' could not be converted: any A & B
2929
public func caller1(x: A & B) -> A & B {
3030
return passThrough(x)
3131
}
3232

33-
// CHECK: error: unexpected error produced: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'addMixedTypeParams' could not be converted: any A & B, any A & C
33+
// CHECK: function-templates.h{{.*}}: error: diagnostic produced elsewhere: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'addMixedTypeParams' could not be converted: any A & B, any A & C
3434
public func caller2(x: A & B, y: A & C) -> A & B {
3535
return addMixedTypeParams(x, y)
3636
}

0 commit comments

Comments
 (0)