Skip to content

[cxx-interop][diags] Fix diagnostics for records inside namespaces. #60215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,12 @@ static Type diagnoseUnknownType(TypeResolution resolution,
.diagnose(comp->getNameLoc(), diag::invalid_member_type,
comp->getNameRef(), kind, parentType)
.highlight(parentRange);

if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
ctx.getClangModuleLoader()->diagnoseMemberValue(
comp->getNameRef().getFullName(), parentType);
}

return ErrorType::get(ctx);
}

Expand Down Expand Up @@ -1308,6 +1314,12 @@ static Type diagnoseUnknownType(TypeResolution resolution,
.diagnose(comp->getNameLoc(), diag::invalid_member_type,
comp->getNameRef(), kind, parentType)
.highlight(parentRange);

if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
ctx.getClangModuleLoader()->diagnoseMemberValue(
comp->getNameRef().getFullName(), parentType);
}

// Note where the type was defined, this can help diagnose if the user
// expected name lookup to find a module when there's a conflicting type.
if (auto typeDecl = parentType->getNominalOrBoundGenericNominal()) {
Expand Down
10 changes: 9 additions & 1 deletion test/Interop/Cxx/class/invalid-class-errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ struct __attribute__((swift_attr("import_unsafe"))) B {
B(const B&) = delete;
};

namespace Namespace {
struct Nested {
Nested(const Nested&) = delete;
};
}

//--- test.swift

import Test

// CHECK: note: record 'A' is not automatically importable: does not have a copy constructor or destructor. Refer to the C++ Interop User Manual to classify this type.
public func test(x: A) { }
// CHECK: note: record 'B' is not automatically importable: does not have a copy constructor or destructor. Refer to the C++ Interop User Manual to classify this type.
public func test(x: B) { }
public func test(x: B) { }
// CHECK: note: record 'Nested' is not automatically importable: does not have a copy constructor or destructor. Refer to the C++ Interop User Manual to classify this type.
public func test(x: Namespace.Nested) { }