diff --git a/lib/Sema/LookupVisibleDecls.cpp b/lib/Sema/LookupVisibleDecls.cpp index f41db09f6c3e1..b86daa1eebad8 100644 --- a/lib/Sema/LookupVisibleDecls.cpp +++ b/lib/Sema/LookupVisibleDecls.cpp @@ -794,7 +794,10 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer { OtherSignature, OtherSignatureType, /*wouldConflictInSwift5*/nullptr, /*skipProtocolExtensionCheck*/true)) { - if (VD->getFormalAccess() > OtherVD->getFormalAccess()) { + if (VD->getFormalAccess() > OtherVD->getFormalAccess() || + //Prefer available one. + (!AvailableAttr::isUnavailable(VD) && + AvailableAttr::isUnavailable(OtherVD))) { PossiblyConflicting.erase(I); PossiblyConflicting.insert(VD); diff --git a/test/IDE/complete_constructor.swift b/test/IDE/complete_constructor.swift index ca65fd02efc13..06666aaaa109e 100644 --- a/test/IDE/complete_constructor.swift +++ b/test/IDE/complete_constructor.swift @@ -47,6 +47,9 @@ // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CLOSURE_IN_INIT_3 | %FileCheck %s -check-prefix=CLOSURE_IN_INIT_1 // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CLOSURE_IN_INIT_4 | %FileCheck %s -check-prefix=CLOSURE_IN_INIT_1 +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AVAILABLE_1 | %FileCheck %s -check-prefix=AVAILABLE_1 +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AVAILABLE_2 | %FileCheck %s -check-prefix=AVAILABLE_2 + func freeFunc() {} //===--- @@ -332,3 +335,33 @@ struct ClosureInInit1 { S(#^CLOSURE_IN_INIT_4^# }() } + +public class AvailableTest { + + @available(swift, obsoleted: 4) + init(opt: Int) { } + + @available(swift, introduced: 4) + init?(opt: Int) { } + + init(normal1: Int) { } + init(normal2: Int) { } + + +} +func testAvailable() { + let _ = AvailableTest(#^AVAILABLE_1^# +// AVAILABLE_1: Begin completions, 3 items +// AVAILABLE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#opt: Int#}[')'][#AvailableTest?#]; name=opt: Int +// AVAILABLE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#normal1: Int#}[')'][#AvailableTest#]; name=normal1: Int +// AVAILABLE_1-DAG: Decl[Constructor]/CurrNominal: ['(']{#normal2: Int#}[')'][#AvailableTest#]; name=normal2: Int +// AVAILABLE_1: End completions + + let _ = AvailableTest.init(#^AVAILABLE_2^# +// AVAILABLE_2: Begin completions, 3 items +// AVAILABLE_2-DAG: Pattern/CurrModule: ['(']{#opt: Int#}[')'][#AvailableTest?#]; name=opt: Int +// AVAILABLE_2-DAG: Pattern/CurrModule: ['(']{#normal1: Int#}[')'][#AvailableTest#]; name=normal1: Int +// AVAILABLE_2-DAG: Pattern/CurrModule: ['(']{#normal2: Int#}[')'][#AvailableTest#]; name=normal2: Int +// AVAILABLE_2: End completions + +}