mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
- Situations where the type of a return statement's result expression doesn't line up with the function's type annotation. - Situations where the type of an initializer expression doesn't line up with its declaration's type pattern. - Situations where we assume a conversion to a built-in protocol must take place, such as in if-statement conditionals. (Addresses rdar://problem/19224776, rdar://problem/19422107, rdar://problem/19422156, rdar://problem/19547806 and lots of other dupes.) Swift SVN r24853
58 lines
1.2 KiB
Swift
58 lines
1.2 KiB
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
struct MyLogicValue : BooleanType {
|
|
var boolValue: Bool {
|
|
return true
|
|
}
|
|
}
|
|
|
|
func useInt(x: Int) {}
|
|
func useDouble(x: Double) {}
|
|
|
|
class B {
|
|
init() {}
|
|
}
|
|
class D1 : B {
|
|
override init() { super.init() }
|
|
}
|
|
class D2 : B {
|
|
override init() { super.init() }
|
|
}
|
|
|
|
func useB(x: B) {}
|
|
func useD1(x: D1) {}
|
|
func useD2(x: D2) {}
|
|
|
|
var a = true ? 1 : 0 // should infer Int
|
|
var b : Double = true ? 1 : 0 // should infer Double
|
|
var c = true ? 1 : 0.0 // should infer Double
|
|
var d = true ? 1.0 : 0 // should infer Double
|
|
|
|
useInt(a)
|
|
useDouble(b)
|
|
useDouble(c)
|
|
useDouble(d)
|
|
|
|
var z = true ? a : b // expected-error{{}} expected-error{{}}
|
|
|
|
var e = true ? B() : B() // should infer B
|
|
var f = true ? B() : D1() // should infer B
|
|
var g = true ? D1() : B() // should infer B
|
|
var h = true ? D1() : D1() // should infer D1
|
|
var i = true ? D1() : D2() // should infer B
|
|
|
|
useB(e)
|
|
useD1(e) // expected-error{{}} expected-note{{}}
|
|
useB(f)
|
|
useD1(f) // expected-error{{}} expected-note{{}}
|
|
useB(g)
|
|
useD1(g) // expected-error{{}} expected-note{{}}
|
|
useB(h)
|
|
useD1(h)
|
|
useB(i)
|
|
useD1(i) // expected-error{{}} expected-note{{}}
|
|
useD2(i) // expected-error{{}} expected-note{{}}
|
|
|
|
var x = MyLogicValue() ? 1 : 0
|
|
var y = 22 ? 1 : 0 // expected-error{{}}
|