Files
swift-mirror/test/Sema/diag_get_vs_set_subscripts.swift
gregomni 18a113e584 We can produce better diagnostics for subscript candidates by noticing when the
subscript is on the destination side of an assignment and restricting matching
overload candidates to only the set-able members.

Also, if we are left with a single candidate, we can recheck unresolved index
expressions with better parameter info.
2017-10-21 14:02:58 -07:00

27 lines
660 B
Swift

// RUN: %target-typecheck-verify-swift
enum Key: Int {
case aKey
case anotherKey // expected-note {{did you mean 'anotherKey'?}}
}
class sr6175 {
var dict: [Key: String] = [:]
func what() -> Void {
dict[.notAKey] = "something" // expected-error {{type 'Key' has no member 'notAKey'}}
}
subscript(i: Int) -> Int {
return i*i
}
subscript(j: Double) -> Double {
get { return j*j }
set {}
}
}
let s = sr6175()
let one: Int = 1
// Should choose the settable subscript to find a problem with, not the get-only subscript
s[one] = 2.5 // expected-error {{cannot convert value of type 'Int' to expected argument type 'Double'}}