Files
swift-mirror/test/expr/cast/array_iteration.swift
Pavel Yaskevich 385fb0c665 [Diagnostics] Make force downcast fix contextual and move it to repairFailures
This way it covers a lot more ground and doesn't conflict with
other fixes.

Another notable change is related to check for IUO associated
with source type, that covers cases like:

```swift
func foo(_ v: NSString!) -> String {
  return v
}
```

Instead of general conversion failure check for IUO enables solver
to introduce force downcast fix.
2019-08-09 01:09:52 -07:00

48 lines
1.1 KiB
Swift

// RUN: %target-typecheck-verify-swift
func doFoo() {}
class View {
var subviews: Array<AnyObject>! = []
}
var rootView = View()
var v = [View(), View()]
rootView.subviews = v
_ = rootView.subviews as! [View]
for view in rootView.subviews as! [View] { // expected-warning{{immutable value 'view' was never used; consider replacing with '_' or removing it}}
doFoo()
}
for view:View in rootView.subviews { // expected-error{{cannot convert sequence element type 'AnyObject' to expected type 'View'}}
doFoo()
}
_ = (rootView.subviews!) as! [View]
_ = (rootView.subviews) as! [View]
var ao: [AnyObject] = []
_ = ao as! [View] // works
var b = Array<(String, Int)>()
for x in b { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
doFoo()
}
var c : Array<(String, Int)>! = Array()
for x in c { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
doFoo()
}
var d : Array<(String, Int)>? = Array()
for x in d! { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
doFoo()
}