Skip to content

Commit 388988f

Browse files
committed
add testcases for diagnostics that got improved along the way, so we don't regress.
1 parent 4511803 commit 388988f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/Constraints/diagnostics.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,44 @@ class SR1594 {
781781
func secondArgumentNotLabeled(a:Int, _ b: Int) { }
782782
secondArgumentNotLabeled(10, 20)
783783
// expected-error@-1 {{unnamed parameter #1 must precede unnamed parameter #0}}
784+
785+
// <rdar://problem/23709100> QoI: incorrect ambiguity error due to implicit conversion
786+
func testImplConversion(a : Float?) -> Bool {}
787+
func testImplConversion(a : Int?) -> Bool {
788+
let someInt = 42
789+
let a : Int = testImplConversion(someInt) // expected-error {{'testImplConversion' produces 'Bool', not the expected contextual result type 'Int'}}
790+
}
791+
792+
// <rdar://problem/23752537> QoI: Bogus error message: Binary operator '&&' cannot be applied to two 'Bool' operands
793+
class Foo23752537 {
794+
var title: String?
795+
var message: String?
796+
}
797+
798+
extension Foo23752537 {
799+
func isEquivalent(other: Foo23752537) {
800+
// expected-error @+1 {{'&&' produces 'Bool', not the expected contextual result type '()'}}
801+
return (self.title != other.title && self.message != other.message)
802+
}
803+
}
804+
805+
806+
// <rdar://problem/22276040> QoI: not great error message with "withUnsafePointer" sametype constraints
807+
func read2(_ p: UnsafeMutablePointer<Void>, maxLength: Int) {}
808+
func read<T : Integer>() -> T? {
809+
var buffer : T
810+
let n = withUnsafePointer(&buffer) { (p) in
811+
read2(UnsafePointer(p), maxLength: sizeof(T)) // expected-error {{cannot convert value of type 'UnsafePointer<_>' to expected argument type 'UnsafeMutablePointer<Void>' (aka 'UnsafeMutablePointer<()>')}}
812+
}
813+
}
814+
815+
func f23213302() {
816+
var s = Set<Int>()
817+
s.subtractInPlace(1) // expected-error {{cannot convert value of type 'Int' to expected argument type 'Set<Int>'}}
818+
}
819+
820+
// <rdar://problem/24202058> QoI: Return of call to overloaded function in void-return context
821+
func rdar24202058(a : Int) {
822+
return a <= 480 // expected-error {{'<=' produces 'Bool', not the expected contextual result type '()'}}
823+
}
824+

0 commit comments

Comments
 (0)