mirror of
https://github.com/apple/swift.git
synced 2026-10-10 13:50:43 +02:00
If we encounter a variable declared after its use within a closure, we can fallback to using an outer result if present. This matches the behavior outside of a closure and generally seems more consistent with the behavior we have if we also find an inner result. rdar://163656720
95 lines
1.4 KiB
Swift
95 lines
1.4 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
// RUN: %target-typecheck-verify-swift -parse-as-library
|
|
|
|
func testLocal() {
|
|
// The first `y` here is considered the inner result.
|
|
do {
|
|
let y = ""
|
|
do {
|
|
let _: String = y
|
|
let y = 0
|
|
_ = y
|
|
}
|
|
}
|
|
do {
|
|
let y = ""
|
|
do {
|
|
_ = {
|
|
let _: String = y
|
|
}
|
|
let y = 0
|
|
_ = y
|
|
}
|
|
}
|
|
do {
|
|
let y = ""
|
|
_ = {
|
|
_ = {
|
|
let _: String = y
|
|
}
|
|
let y = 0
|
|
_ = y
|
|
}
|
|
}
|
|
do {
|
|
let y = ""
|
|
func bar() {
|
|
_ = {
|
|
let _: String = y
|
|
}
|
|
let y = 0
|
|
_ = y
|
|
}
|
|
}
|
|
}
|
|
|
|
let topLevelString = ""
|
|
|
|
func testTopLevel() {
|
|
// Here 'topLevelString' is now an outer result.
|
|
do {
|
|
let _: String = topLevelString
|
|
let topLevelString = 0
|
|
_ = topLevelString
|
|
}
|
|
do {
|
|
_ = {
|
|
let _: String = topLevelString
|
|
}
|
|
let topLevelString = 0
|
|
_ = topLevelString
|
|
}
|
|
_ = {
|
|
_ = {
|
|
let _: String = topLevelString
|
|
}
|
|
let topLevelString = 0
|
|
_ = topLevelString
|
|
}
|
|
func bar() {
|
|
_ = {
|
|
let _: String = topLevelString
|
|
}
|
|
let topLevelString = 0
|
|
_ = topLevelString
|
|
}
|
|
}
|
|
|
|
struct TestLocalPropertyShadowing {
|
|
var str: String
|
|
|
|
func foo() {
|
|
{ _ = str }()
|
|
let str = str
|
|
_ = str
|
|
}
|
|
func bar() {
|
|
let str = { str }
|
|
_ = str
|
|
}
|
|
func baz() {
|
|
let str = str
|
|
_ = str
|
|
}
|
|
}
|