swiftc selects UnsafePointer == when resolving overload in generic context involving arrays

Originator:rix.rob
Number:rdar://22996431 Date Originated:06-Oct-2015 04:07 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.0.1 (7A1001)
Classification:Enhancement Reproducible:Always
 
Summary:
swiftc coerces arrays to UnsafePointer and thus also allows == in generic contexts when the arguments in question are arrays not returned from closure literals. Note that this _only_ works in generic contexts; you can’t let-bind == if the arguments are arrays.


Steps to Reproduce:
1. This code:
struct A {} // not Equatable!

func callsToThisShouldNotCompileButTotallyDo<A>(a: A, _ test: (A, A) -> Bool, _ b: A) -> Bool {
	return test(a, b)
}

func doesNotEvenCompile<A>(a: () -> A, _ test: (A, A) -> Bool, _ b: () -> A) -> Bool {
	return test(a(), b())
}

for i in 0..<1000000 {
	assert(callsToThisShouldNotCompileButTotallyDo([ A(), A() ], ==, [ A(), A() ]), "failed at comparison \(i)")
}


Expected Results:
should not compile


Actual Results:
but totally does.


Regression:
If you call callsToThisShouldNotCompileButTotallyDo, it compiles, and should not. At runtime, it fails deterministically.
If you call doesNotEvenCompile, it does not even compile. This is correct.


Notes:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!