mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Try to fix constraint system in a way where member reference is going to be defined in terms of its use, which makes it seem like parameters match arguments exactly. Such helps to produce solutions and diagnose failures related to missing members precisely. These changes would be further extended to diagnose use of unavailable members and other structural member failures. Resolves: rdar://problem/34583132 Resolves: rdar://problem/36989788 Resolved: rdar://problem/39586166 Resolves: rdar://problem/40537782 Resolves: rdar://problem/46211109
61 lines
1.3 KiB
Swift
61 lines
1.3 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
struct X { }
|
|
struct Y { }
|
|
|
|
struct WithOverloadedSubscript {
|
|
subscript(i: Int) -> X {
|
|
get {}
|
|
set {}
|
|
}
|
|
subscript(i: Int) -> Y {
|
|
get {}
|
|
set {}
|
|
}
|
|
}
|
|
|
|
func test_assign() {
|
|
var a = WithOverloadedSubscript()
|
|
a[0] = X()
|
|
a[0] = Y()
|
|
}
|
|
|
|
var i: X
|
|
var j: X
|
|
var f: Y
|
|
func getXY() -> (X, Y) {}
|
|
var ift : (X, Y)
|
|
var ovl = WithOverloadedSubscript()
|
|
|
|
var slice: [X]
|
|
|
|
i = j
|
|
(i, f) = getXY()
|
|
(i, f) = ift
|
|
(i, f) = (i, f)
|
|
(ovl[0], ovl[0]) = ift
|
|
(ovl[0], ovl[0]) = (i, f)
|
|
(_, ovl[0]) = (i, f)
|
|
(ovl[0], _) = (i, f)
|
|
_ = (i, f)
|
|
slice[7] = i
|
|
|
|
slice[7] = f // expected-error{{cannot assign value of type 'Y' to type 'X'}}
|
|
|
|
slice[7] = _ // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
|
|
|
|
func value(_ x: Int) {}
|
|
func value2(_ x: inout Int) {}
|
|
value2(&_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
|
|
value(_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
|
|
|
|
|
|
// <rdar://problem/23798944> = vs. == in Swift if string character count statement causes segmentation fault
|
|
func f23798944() {
|
|
let s = ""
|
|
if s.count = 0 { // expected-error {{use of '=' in a boolean context, did you mean '=='?}}
|
|
}
|
|
}
|
|
|
|
.sr_3506 = 0 // expected-error {{type 'Int' has no member 'sr_3506'}}
|