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
12 changes: 12 additions & 0 deletions lib/Sema/CSOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ void forEachDisjunctionChoice(
if (!decl)
continue;

// Ignore declarations that come from implicitly imported modules
// when `MemberImportVisibility` feature is enabled otherwise
// we might end up favoring an overload that would be diagnosed
// as unavailable later.
if (cs.getASTContext().LangOpts.hasFeature(
Feature::MemberImportVisibility)) {
if (auto *useDC = constraint->getOverloadUseDC()) {
if (!useDC->isDeclImported(decl))
continue;
}
}

// If disjunction choice is unavailable or disfavored we cannot
// do anything with it.
if (decl->getAttrs().hasAttribute<DisfavoredOverloadAttr>() ||
Expand Down
39 changes: 39 additions & 0 deletions test/Constraints/member_import_visibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src

/// Build the library A
// RUN: %target-swift-frontend -emit-module %t/src/A.swift \
// RUN: -module-name A \
// RUN: -emit-module-path %t/A.swiftmodule

/// Build the library B
// RUN: %target-swift-frontend -I %t -emit-module %t/src/B.swift \
// RUN: -module-name B \
// RUN: -emit-module-path %t/B.swiftmodule

// RUN: %target-swift-frontend -typecheck -I %t %t/src/Main.swift %t/src/Other.swift -enable-upcoming-feature MemberImportVisibility

// REQUIRES: swift_feature_MemberImportVisibility

//--- A.swift
public struct Test {
public init(a: Double) { }
}

//--- B.swift
import A

extension Test {
public init(a: Int) { fatalError() }
}

//--- Main.swift
import A

func test() {
_ = Test(a: 0) // Ok, selects the overload that takes Double.
}

//--- Other.swift
import B