Skip to content
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
9 changes: 9 additions & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10148,6 +10148,15 @@ static void finishTypeWitnesses(
break;
}

if (!satisfied && assocType->hasDefaultDefinitionType()) {
auto defaultType = assocType->getDefaultDefinitionType();
auto subMap =
selfType->getContextSubstitutionMap(assocType->getDeclContext());
defaultType = defaultType.subst(subMap);
conformance->setTypeWitness(assocType, defaultType, assocType);
satisfied = true;
}

if (!satisfied) {
ABORT([&](auto &out) {
out << "Cannot look up associated type for imported conformance:\n";
Expand Down
37 changes: 37 additions & 0 deletions test/Interop/Cxx/class/conforms-to-associated-types.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/include)
// RUN: split-file %s %t
//
// RUN: %target-swift-frontend -typecheck -module-name a -cxx-interoperability-mode=default -I %t/include %t/a.swift

//--- include/module.modulemap
module cxx {
header "header.h"
export *
}

//--- include/header.h
struct S {
S() {}
} __attribute__((swift_attr("conforms_to:a.P")));

struct S2 {
S2() {}
using A = S2;
} __attribute__((swift_attr("conforms_to:a.P")));

//--- a.swift
import cxx
public protocol P {
associatedtype A = Int
func foo(_: A)
}
extension P {
func foo(_: A) {}
}
func test(s: S) {
let _ = s.foo(0)
}
func test2(s: S2) {
let _ = s.foo(s)
}