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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public struct Y<T> { }

extension Y: P where T: P { }

public struct Z: P { }
public struct Z: P {
public init() {}
}

infix operator <<<
infix operator >>>
Expand All @@ -25,6 +27,7 @@ extension X {
public static func <<<(a: Self, b: Self) -> Self { a }

public struct NestedInA {}
public protocol ProtoNestedInA {}
}

extension Y {
Expand All @@ -33,6 +36,10 @@ extension Y {
public static func <<<(a: Self, b: Self) -> Self { a }
}

extension P where Self == Z {
public static var zInA: Z { Z() }
}

public enum EnumInA {
case caseInA
}
Expand Down
8 changes: 8 additions & 0 deletions test/NameLookup/Inputs/MemberImportVisibility/members_B.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ extension X {

public struct NestedInB {}
package struct NestedInB_package {}
public protocol ProtoNestedInB {}
}

// Members with the same names are also declared in C.
extension X {
public init(_ x: Int) { self.init() }
public func ambiguous() -> Int { return 1 }
public func ambiguousDisfavored() -> Int { return 1 }
public var ambiguousProp: Bool { return false }
public struct AmbiguousNestedType { }
}

extension Y {
Expand All @@ -30,6 +33,11 @@ extension Y {
public static func >>>(a: Self, b: Self) -> Self { b }
}

extension P where Self == Z {
public static var zInB: Z { Z() }
public static var zAmbiguous: Z { Z() }
}

public enum EnumInB {
case caseInB
}
Expand Down
8 changes: 8 additions & 0 deletions test/NameLookup/Inputs/MemberImportVisibility/members_C.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ extension X {
public static func <>(a: Self, b: Self) -> Self { a }

public struct NestedInC {}
public protocol ProtoNestedInC {}
}

// Members with the same names are also declared in B.
extension X {
public init(_ x: Bool) { self.init() }
public func ambiguous() -> Bool { return false }
@_disfavoredOverload public func ambiguousDisfavored() -> Bool { return false }
public var ambiguousProp: Bool { return true }
public struct AmbiguousNestedType { }
}

extension Y {
Expand All @@ -28,6 +31,11 @@ extension Y {
public static func <>(a: Self, b: Self) -> Self { a }
}

extension P where Self == Z {
public static var zInC: Z { Z() }
public static var zAmbiguous: Z { Z() }
}

public enum EnumInC {
case caseInC
}
Expand Down
53 changes: 37 additions & 16 deletions test/NameLookup/member_import_visibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// REQUIRES: swift_feature_MemberImportVisibility

import members_C
// expected-member-visibility-note 20{{add import of module 'members_B'}}{{1-1=internal import members_B\n}}
// expected-member-visibility-note 28{{add import of module 'members_B'}}{{1-1=internal import members_B\n}}


func testExtensionMembers(x: X, y: Y<Z>) {
Expand Down Expand Up @@ -66,35 +66,47 @@ func testOperatorMembers(x: X, y: Y<Z>) {
_ = y <> y
}

struct GenericType<T> { }

extension X {
var testProperties: (Bool, Bool, Bool, Bool) {
return (
propXinA,
propXinB, // expected-member-visibility-error{{property 'propXinB' is not available due to missing import of defining module 'members_B'}}
propXinB_package, // expected-member-visibility-error{{property 'propXinB_package' is not available due to missing import of defining module 'members_B}}
propXinC
)
}
var testPropertyInA: Bool { propXinA }
var testPropertyInB: Bool { propXinB } // expected-member-visibility-error {{property 'propXinB' is not available due to missing import of defining module 'members_B'}}
var testPropertyInB_package: Bool { propXinB_package } // expected-member-visibility-error{{property 'propXinB_package' is not available due to missing import of defining module 'members_B}}
var testPropertyInC: Bool { propXinC }

// This is not diagnosed in either mode (the property from the nearest scope is always preferred
var testAmbiguousProp: Bool { ambiguousProp }

func testNestedTypes() {
func testTypeExpressions() {
_ = NestedInA.self
_ = NestedInB.self // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
_ = NestedInB_package.self // expected-member-visibility-error{{struct 'NestedInB_package' is not available due to missing import of defining module 'members_B'}}
_ = (NestedInB).self // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
_ = (NestedInA, NestedInB, NestedInC).self // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
_ = GenericType<NestedInB>.self // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
_ = NestedInC.self
_ = AmbiguousNestedType.self
}

var nestedInA: NestedInA { fatalError() }
var nestedInB: NestedInB { fatalError() } // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
var nestedInB_package: NestedInB_package { fatalError() } // expected-member-visibility-error{{struct 'NestedInB_package' is not available due to missing import of defining module 'members_B'}}
var nestedInC: NestedInC { fatalError() }
var hasNestedInAType: NestedInA { fatalError() }
var hasNestedInBType: NestedInB { fatalError() } // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
var hasNestedInB_packageType: NestedInB_package { fatalError() } // expected-member-visibility-error{{struct 'NestedInB_package' is not available due to missing import of defining module 'members_B'}}
var hasNestedInBTrivialTupleType: (NestedInB) { fatalError() } // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
var hasTupleTypeContainingNestedInB: (NestedInA, NestedInB, NestedInC) { fatalError() } // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
var hasNestedInBAsGenericTypeParameter: GenericType<NestedInB> { fatalError() } // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
var hasNestedInCType: NestedInC { fatalError() }

func hasNestedInAInGenericReqs<T>(_ t: T) where T: ProtoNestedInA { }
func hasNestedInBInGenericReqs<T>(_ t: T) where T: ProtoNestedInB { } // expected-member-visibility-error{{protocol 'ProtoNestedInB' is not available due to missing import of defining module 'members_B'}}
func hasNestedInCInGenericReqs<T>(_ t: T) where T: ProtoNestedInC { }
}

extension X.NestedInA {}
extension X.NestedInB {} // expected-member-visibility-error{{struct 'NestedInB' is not available due to missing import of defining module 'members_B'}}
extension X.NestedInB_package {} // expected-member-visibility-error{{struct 'NestedInB_package' is not available due to missing import of defining module 'members_B'}}
extension X.NestedInC {}

func testTopLevelTypes() {
func testTypeExpressionsReferencingTopLevelTypes() {
_ = EnumInA.self
_ = EnumInB.self // expected-error{{cannot find 'EnumInB' in scope}}
_ = EnumInB_package.self // expected-error{{cannot find 'EnumInB_package' in scope}}
Expand All @@ -107,7 +119,8 @@ class DerivedFromClassInC: DerivedClassInC {
override func methodInC() {}
}

struct ConformsToProtocolInA: ProtocolInA {} // expected-member-visibility-error{{type 'ConformsToProtocolInA' does not conform to protocol 'ProtocolInA'}} expected-member-visibility-note {{add stubs for conformance}}
// FIXME: Visibility of defaultedRequirementInB() should be diagnosed (rdar://154237873)
struct ConformsToProtocolInA: ProtocolInA {} // expected-member-visibility-error{{type 'ConformsToProtocolInA' does not conform to protocol 'ProtocolInA'}} expected-member-visibility-note {{add stubs for conformance}}{{44-44=\n func defaultedRequirementInB() {\n <#code#>\n \}\n}}

func testInheritedMethods(
a: BaseClassInA,
Expand All @@ -128,3 +141,11 @@ func testInheritedMethods(
b.overriddenMethod() // expected-member-visibility-error{{instance method 'overriddenMethod()' is not available due to missing import of defining module 'members_B'}}
c.overriddenMethod()
}

func testLeadingDotSyntax() {
func takesP<T: P>(_: T) { }
takesP(.zInA)
takesP(.zInB) // expected-member-visibility-error{{static property 'zInB' is not available due to missing import of defining module 'members_B'}}
takesP(.zInC)
takesP(.zAmbiguous)
}