1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
// RUN: not %swift -typecheck -target %target-triple %s -emit-fixits-path %t.remap -I %S/Inputs
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
class Base {}
class Derived : Base {}
var b : Base
b as! Derived
b as! Derived
b
var opti : Int?
// Add bang.
var i : Int = opti!
// But remove unnecessary bang.
var i2 : Int = i
struct MyMask : OptionSet {
init(_ rawValue: UInt) {}
init(rawValue: UInt) {}
init(nilLiteral: ()) {}
var rawValue: UInt { return 0 }
static var allZeros: MyMask { return MyMask(0) }
static var Bingo: MyMask { return MyMask(1) }
}
let _: MyMask = []
func supported() -> MyMask {
return MyMask(rawValue: UInt(MyMask.Bingo))
}
struct MyEventMask2 : OptionSet {
init(rawValue: UInt64) {}
var rawValue: UInt64 { return 0 }
}
func sendIt(_: MyEventMask2) {}
func sendItOpt(_: MyEventMask2?) {}
func sendItOpt3(_: MyEventMask2???) {}
func testMask1(a: Int) {
sendIt(MyEventMask2(rawValue: UInt64(a)))
}
func testMask2(a: UInt64) {
sendIt(MyEventMask2(rawValue: a))
}
func testMask3(a: MyEventMask2) {
testMask1(a: Int(a.rawValue))
}
func testMask4(a: MyEventMask2) {
testMask2(a: a.rawValue)
}
func testMask5(a: Int) {
sendItOpt(MyEventMask2(rawValue: UInt64(a)))
}
func testMask6(a: Int) {
sendItOpt(MyEventMask2(rawValue: UInt64(a)))
}
func testMask7(a: Int?) {
sendItOpt(a.map { MyEventMask2(rawValue: UInt64($0)) })
}
func testMask8(a: UInt64?) {
sendItOpt(a.map { MyEventMask2(rawValue: $0) })
}
func testMask9(a: Any) {
sendItOpt((a as? Int).map { MyEventMask2(rawValue: UInt64($0)) })
}
func testMask10(a: Int?) {
sendIt(a) // no fix, nullability mismatch.
}
func testMask11(a: MyEventMask2?) {
testMask7(a: a.map { Int($0.rawValue) })
}
func testMask12(a: MyEventMask2?) {
testMask8(a: a.map { $0.rawValue })
}
func testMask13(a: MyEventMask2?) {
testMask1(a: a) // no fix, nullability mismatch.
}
func testMask14() {
sendIt(MyEventMask2(rawValue: 1))
sendItOpt(MyEventMask2(rawValue: 2))
}
struct Wrapper {
typealias InnerMask = MyEventMask2
}
func sendItInner(_: Wrapper.InnerMask) {}
func testInnerMask(a: UInt64) {
sendItInner(Wrapper.InnerMask(rawValue: a))
}
struct SomeName : RawRepresentable {
init(_ rawValue: String) {}
init(rawValue: String) {}
var rawValue: String { return "" }
}
func testPassSomeName(_: SomeName) {}
func testConvertSomeName(s: String) {
testPassSomeName(SomeName(rawValue: "\(s)}"))
}
class WrappedClass {}
class WrappedClassSub: WrappedClass {}
struct ClassWrapper : RawRepresentable {
var rawValue: WrappedClass
}
func testPassAnyObject(_: AnyObject) {}
func testPassAnyObjectOpt(_: AnyObject?) {}
func testPassWrappedSub(_: WrappedClassSub) {}
func testConvertClassWrapper(_ x: ClassWrapper, _ sub: WrappedClassSub) {
testPassAnyObject(x.rawValue)
testPassAnyObjectOpt(x.rawValue)
testPassWrappedSub(x)
let iuo: ClassWrapper! = x
testPassAnyObject(iuo)
testPassAnyObjectOpt(iuo.map { $0.rawValue })
let _: ClassWrapper = ClassWrapper(rawValue: sub)
let _: ClassWrapper = ClassWrapper(rawValue: x.rawValue)
// FIXME: This one inserts 'as!', which is incorrect.
let _: ClassWrapper = sub as AnyObject as! ClassWrapper
}
enum MyEnumType : UInt32 {
case invalid
}
_ = MyEnumType.invalid
func goo(e : Error) {
var e = e
}
func goo2(e: Error) { var e = e }
func goo3(e: Int) { var e = e; e = 3 }
protocol A {
func bar(s: Int)
}
extension A {
func bar(s: Int) {
var s = s
s += 5
}
}
func baz(x: Int) {
var x = x
x += 10
}
func foo(y: String, x: inout Int) {
}
struct Test1 : OptionSet {
init(rawValue: Int) {}
var rawValue: Int { return 0 }
}
print("", false)
func ftest1() {
// Don't replace the variable name with '_'
let myvar = 0
}
func ftest2(x: @escaping (Int) -> Int) {}
protocol SomeProt {
func protMeth(p: Int)
}
@objc protocol SomeObjCProt {
func objcprotMeth(p: Int)
}
class Test2 : SomeProt, SomeObjCProt {
func protMeth(_ p: Int) {}
func instMeth(p: Int) {}
func instMeth2(p: Int, p2: Int) {}
func objcprotMeth(_ p: Int) {}
}
@objc class Test3 : SomeObjCProt {
func objcprotMeth(_ p: Int) {}
}
class SubTest2 : Test2 {
override func instMeth(_ p: Int) {}
}
Test2().instMeth(0)
Test2().instMeth2(0, p2:1)
func recit(_: Int32) {}
func ftest3(_ fd: CInt) {
recit(fd)
}
func ftest4(_ fd: UInt) {
recit(Int32(fd))
}
func letToVar1() {
var x = 1
if x == 2 {
x += 3
}
var y = ""
y.append("as")
y.append("df")
}
class Node {}
class Graph<NodeType : Node> {}
var graph: Graph<Node>
class Node2 {}
class Graph2<NodeType1 : Node, NodeType2 : Node2> {}
var graph: Graph2<Node, Node2>
@objc protocol ObjCProt { }
class Graph3<NodeType : ObjCProt> {}
var graph: Graph3<ObjCProt>
class Graph4<NodeType : SomeProt> {}
var graph: Graph4<<#NodeType: SomeProt#>>
var graphAgain = Graph4<<#NodeType: SomeProt#>>()
class GraphCombo<NodeType : SomeProt & ObjCProt> {}
var graph: GraphCombo<<#NodeType: ObjCProt & SomeProt#>>
func evilCommas(s: String) {
_ = s[s.startIndex..<<#editorplaceholder#>]
_ = true ? s[s.startIndex..<<#editorplaceholder#>] : ""
_ = [s.startIndex..<<#editorplaceholder#>]
}
import Empty
func testGenericSig(x: Empty<Int>) -> Empty<String> {}
class NonObjC {}
protocol NonObjCProtocol {}
@objc class IBIssues {
@IBOutlet static private var ibout1: IBIssues!
@IBOutlet private var ibout2: NonObjC!
@IBOutlet private var ibout3: NonObjCProtocol!
@IBOutlet private let ibout4: IBIssues!
@IBOutlet private var ibout5: [[IBIssues]]!
@IBOutlet private var ibout6: [String: String]!
@IBInspectable static private var ibinspect1: IBIssues!
@IBAction static func ibact() {}
@IBSegueAction static func ibsegact(_: String, _: IBIssues) -> IBIssues { return self }
}
@IBDesignable extension SomeProt {}
func attrNowOnType(foo: ()->()) {}
class InitDynType {
init() {}
func notInit() {
self.init()
}
}
class NoSemi {
enum Bar { case bar }
var foo: .Bar = .bar
}
func fnWithClosure(c: @escaping ()->()) {}
func testescape(rec: @escaping ()->()) {
fnWithClosure { rec() }
}
func testDeprecatedAttr() -> Int { return 0 }
protocol Prot1 {}
protocol Prot2 {
associatedtype Ty = Prot1
}
class Cls1 : Prot1 {}
func testwhere<T: Prot2>(_: T) where T.Ty == Cls1 {}
enum E {
case abc
}
func testEnumRename() { _ = E.Abc }
func testAnyToAnyObject(x: Any) {
(x as AnyObject).instMeth(p: 1)
}
func testProtocolCompositionSyntax() {
var _: Any
var _: Prot1
var _: Prot1 & Prot2
}
func disable_unnamed_param_reorder(p: Int, _: String) {}
disable_unnamed_param_reorder(0, "") // no change.
prefix operator *****
class BoolFoo : Bool {
var boolValue: Bool {return false}
}
func testBoolValue(a : BoolFoo) {
if a.boolValue { }
guard a.boolValue {}
if (a as BoolFoo).boolValue {}
}
protocol P1 {}
protocol P2 {}
var a : (P1 & P2)?
var a2 : P1= 17 as! P1
class TestOptionalMethodFixit {
func test() {}
}
|