mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
19 lines
812 B
Swift
19 lines
812 B
Swift
// RUN: %target-swift-frontend -typecheck -swift-version 5 %s -verify
|
|
|
|
func testPopFirst() {
|
|
let str = "abc"
|
|
let charView: String.CharacterView // expected-error{{'CharacterView' is unavailable: Please use String directly}}
|
|
_ = str.characters // expected-error{{'characters' is unavailable: Please use String directly}}
|
|
dump(charView)
|
|
|
|
var substr = str[...]
|
|
_ = substr.popFirst() // ok
|
|
_ = substr.characters.popFirst() // expected-error{{'characters' is unavailable: Please use Substring directly}}
|
|
_ = substr.unicodeScalars.popFirst() // ok
|
|
|
|
let charSubView: Substring.CharacterView // expected-error{{'CharacterView' is unavailable: Please use Substring directly}}
|
|
_ = substr.characters // expected-error{{'characters' is unavailable: Please use Substring directly}}
|
|
dump(charSubView)
|
|
}
|
|
|