Files
swift-mirror/test/Compatibility/accessibility_compound.swift
Jordan Rose 9489f10ce1 Use Swift-3-style access checking to downgrade errors to warnings.
...instead of just ignoring the errors in certain cases, in service of
source compatibility.

Swift 3.0 wasn't nearly as strict as checking access control for types
because it didn't look at the TypeRepr at all (except to highlight a
particular part of the type in diagnostics). It also looked through
typealiases in certain cases. Approximate this behavior by running the
access checking logic for Types (rather than TypeReprs), and downgrade
access violation errors to warnings when the checks disagree.

Part of rdar://problem/29855782.
2017-01-13 14:34:50 -08:00

42 lines
2.1 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 3
public struct Pair<A, B> {}
public struct PublicStruct {
public struct Inner {}
internal struct Internal {}
}
private typealias PrivateAlias = PublicStruct // expected-note * {{type declared here}}
public let a0 = nil as PrivateAlias.Inner? // expected-warning {{constant should not be declared public because its type 'PrivateAlias.Inner?' uses a private type}}
public let a: PrivateAlias.Inner? // expected-warning {{constant should not be declared public because its type uses a private type}}
public let b: PrivateAlias.Internal? // expected-error {{constant cannot be declared public because its type uses an internal type}}
public let c: Pair<PrivateAlias.Inner, PublicStruct.Internal>? // expected-error {{constant cannot be declared public because its type uses an internal type}}
public let c2: Pair<PublicStruct.Internal, PrivateAlias.Inner>? // expected-error {{constant cannot be declared public because its type uses an internal type}}
public let d: PrivateAlias? // expected-error {{constant cannot be declared public because its type uses a private type}}
// rdar://problem/21408035
private class PrivateBox<T> { // expected-note * {{type declared here}}
typealias ValueType = T
typealias AlwaysFloat = Float
}
let boxUnboxInt: PrivateBox<Int>.ValueType = 0 // expected-warning {{constant should be declared private because its type uses a private type}}
let boxFloat: PrivateBox<Int>.AlwaysFloat = 0 // expected-error {{constant must be declared private or fileprivate because its type uses a private type}}
private protocol PrivateProto {
associatedtype Inner
}
extension PublicStruct: PrivateProto {}
private class SpecificBox<T: PrivateProto> { // expected-note * {{type declared here}}
typealias InnerType = T.Inner
typealias AlwaysFloat = Float
}
let specificBoxUnboxInt: SpecificBox<PublicStruct>.InnerType = .init() // expected-warning {{constant should be declared private because its type uses a private type}}
let specificBoxFloat: SpecificBox<PublicStruct>.AlwaysFloat = 0 // expected-error {{constant must be declared private or fileprivate because its type uses a private type}}