Files
swift-mirror/test/Sema/availability_compound.swift
Slava Pestov 94e999a1b5 Sema: Pull availability checking out of resolveType()
We used to diagnose references to unavailable declarations in
two places:

- inside Exprs, right after type checking the expression
- inside TypeReprs, from resolveType()

In broad terms, resolveType() is called with TypeReprs
stored inside both Stmts and Decls.

To handle the first case, I added a new overload of
diagAvailability() that takes a Stmt, to be called from
typeCheckStmt(). This doesn't actually walk into any Exprs
stored inside the statement; this means it only walks
Patterns and such.

For the second case, a new DeclAvailabilityChecker is
now defined in TypeCheckAccess.cpp. It's structure is
analogous to the other three walkers there:

- AccessControlChecker
- UsableFromInlineChecker
- ExportabilityChecker

The new implementation of availability checking for types
introduces a lot more code than the old online logic
it replaces. However, I hope to consolidate some of the
code duplication among the four checkers that are defined
in TypeCheckAccess.cpp, and do some other cleanups that
will make the benefit of the new approach apparent.
2020-10-14 23:42:02 -04:00

28 lines
1.4 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 4
public struct Pair<A, B> {}
public struct PublicStruct {
public struct Inner {}
@available(*, unavailable)
internal struct Obsolete {} // expected-note * {{marked unavailable here}}
}
@available(*, unavailable, renamed: "PublicStruct")
public typealias ObsoleteAlias = PublicStruct // expected-note * {{marked unavailable here}}
public let a: ObsoleteAlias.Inner? // expected-error {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}
public let b: ObsoleteAlias.Obsolete? // expected-error {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}
// expected-error@-1 {{constant cannot be declared public because its type uses an internal type}}
public let c: Pair<ObsoleteAlias.Inner, PublicStruct.Obsolete>? // expected-error {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}
// expected-error@-1 {{'Obsolete' is unavailable}}
// expected-error@-2 {{constant cannot be declared public because its type uses an internal type}}
public let c2: Pair<PublicStruct.Obsolete, ObsoleteAlias.Inner>? // expected-error {{'Obsolete' is unavailable}}
// expected-error@-1 {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}
// expected-error@-2 {{constant cannot be declared public because its type uses an internal type}}
public let d: ObsoleteAlias? // expected-error {{'ObsoleteAlias' has been renamed to 'PublicStruct'}}