Skip to content

Commit 334f22c

Browse files
Merge pull request #60925 from AnthonyLatsis/migrate-test-suite-to-gh-issues-19
Gardening: Migrate test suite to GH issues p. 19
2 parents 3bc4c32 + cafcb86 commit 334f22c

File tree

3 files changed

+189
-164
lines changed

3 files changed

+189
-164
lines changed

test/Sema/diag_ambiguous_overloads.swift

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -64,93 +64,102 @@ class Variadic {
6464
Variadic.foo(1.0, 2.0, 3.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
6565

6666

67-
//=-------------- SR-7918 --------------=/
68-
class sr7918_Suit {
69-
static func foo<T: Any>(_ :inout T) {}
70-
static func foo() {}
71-
}
72-
73-
class sr7918_RandomNumberGenerator {}
74-
75-
let myRNG = sr7918_RandomNumberGenerator() // expected-note {{change 'let' to 'var' to make it mutable}}
76-
_ = sr7918_Suit.foo(&myRNG) // expected-error {{cannot pass immutable value as inout argument: 'myRNG' is a 'let' constant}}
67+
// https://github.com/apple/swift/issues/50453
68+
do {
69+
class Suit {
70+
static func foo<T: Any>(_ :inout T) {}
71+
static func foo() {}
72+
}
7773

74+
class RandomNumberGenerator {}
7875

79-
//=-------------- SR-7786 --------------=/
80-
struct sr7786 {
81-
func foo() -> UInt { return 0 }
82-
func foo<T: UnsignedInteger>(bar: T) -> T { // expected-note {{where 'T' = 'Int'}}
83-
return bar
84-
}
76+
let myRNG = RandomNumberGenerator() // expected-note {{change 'let' to 'var' to make it mutable}}
77+
_ = Suit.foo(&myRNG) // expected-error {{cannot pass immutable value as inout argument: 'myRNG' is a 'let' constant}}
8578
}
8679

87-
let s = sr7786()
88-
let a = s.foo()
89-
let b = s.foo(bar: 123) // expected-error {{instance method 'foo(bar:)' requires that 'Int' conform to 'UnsignedInteger'}}
90-
let c: UInt = s.foo(bar: 123)
91-
let d = s.foo(bar: 123 as UInt)
92-
80+
// https://github.com/apple/swift/issues/50325
81+
do {
82+
struct S {
83+
func foo() -> UInt { return 0 }
84+
func foo<T: UnsignedInteger>(bar: T) -> T { // expected-note {{where 'T' = 'Int'}}
85+
return bar
86+
}
87+
}
9388

94-
//=-------------- SR-7440 --------------=/
95-
struct sr7440_ITunesGenre {
96-
let genre: Int // expected-note {{'genre' declared here}}
97-
let name: String
89+
let s = S()
90+
let a = s.foo()
91+
let b = s.foo(bar: 123) // expected-error {{instance method 'foo(bar:)' requires that 'Int' conform to 'UnsignedInteger'}}
92+
let c: UInt = s.foo(bar: 123)
93+
let d = s.foo(bar: 123 as UInt)
9894
}
99-
class sr7440_Genre {
100-
static func fetch<B: BinaryInteger>(genreID: B, name: String) {}
101-
static func fetch(_ iTunesGenre: sr7440_ITunesGenre) -> sr7440_Genre {
102-
return sr7440_Genre.fetch(genreID: iTunesGenre.genreID, name: iTunesGenre.name)
103-
// expected-error@-1 {{value of type 'sr7440_ITunesGenre' has no member 'genreID'; did you mean 'genre'?}}
104-
// expected-error@-2 {{cannot convert return expression of type '()' to return type 'sr7440_Genre'}}
95+
96+
// https://github.com/apple/swift/issues/49983
97+
do {
98+
struct ITunesGenre {
99+
let genre: Int // expected-note {{'genre' declared here}}
100+
let name: String
101+
}
102+
class Genre {
103+
static func fetch<B: BinaryInteger>(genreID: B, name: String) {}
104+
static func fetch(_ iTunesGenre: ITunesGenre) -> Genre {
105+
return Genre.fetch(genreID: iTunesGenre.genreID, name: iTunesGenre.name)
106+
// expected-error@-1 {{value of type 'ITunesGenre' has no member 'genreID'; did you mean 'genre'?}}
107+
// expected-error@-2 {{cannot convert return expression of type '()' to return type 'Genre'}}
108+
}
105109
}
106110
}
107111

112+
// https://github.com/apple/swift/issues/47730
108113

109-
//=-------------- SR-5154 --------------=/
110-
protocol sr5154_Scheduler {
114+
protocol Scheduler {
111115
func inBackground(run task: @escaping () -> Void)
112116
}
113117

114-
extension sr5154_Scheduler {
115-
func inBackground(run task: @escaping () -> [Count], completedBy resultHandler: @escaping ([Count]) -> Void) {}
118+
extension Scheduler {
119+
func inBackground(run task: @escaping () -> [Count],
120+
completedBy resultHandler: @escaping ([Count]) -> Void) {}
116121
}
117122

118123
struct Count { // expected-note {{'init(title:)' declared here}}
119124
let title: String
120125
}
121126

122-
func getCounts(_ scheduler: sr5154_Scheduler, _ handler: @escaping ([Count]) -> Void) {
127+
func getCounts(_ scheduler: Scheduler, _ handler: @escaping ([Count]) -> Void) {
123128
scheduler.inBackground(run: {
124129
return [Count()] // expected-error {{missing argument for parameter 'title' in call}}
125130
}, completedBy: { // expected-error {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}} {{20-20= _ in}}
126131
})
127132
}
128133

129-
// SR-12689
130-
func SR12689(_ u: UnsafeBufferPointer<UInt16>) {}
134+
// https://github.com/apple/swift/issues/55133
135+
do {
136+
func f(_ u: UnsafeBufferPointer<UInt16>) {}
131137

132-
let array : [UInt16] = [1, 2]
138+
let array : [UInt16]
133139

134-
array.withUnsafeBufferPointer {
135-
_ = SR12689(UnsafeRawPointer($0).bindMemory(to: UInt16.self, capacity: 1)) // expected-error {{cannot convert value of type 'UnsafePointer<UInt16>' to expected argument type 'UnsafeBufferPointer<UInt16>'}}
136-
// expected-error@-1 {{cannot convert value of type 'UnsafeBufferPointer<UInt16>' to expected argument type 'UnsafeMutableRawPointer'}}
137-
}
140+
array.withUnsafeBufferPointer {
141+
_ = f(UnsafeRawPointer($0).bindMemory(to: UInt16.self, capacity: 1)) // expected-error {{cannot convert value of type 'UnsafePointer<UInt16>' to expected argument type 'UnsafeBufferPointer<UInt16>'}}
142+
// expected-error@-1 {{cannot convert value of type 'UnsafeBufferPointer<UInt16>' to expected argument type 'UnsafeMutableRawPointer'}}
143+
}
138144

139-
array.withUnsafeBufferPointer {
140-
_ = UnsafeRawPointer($0) as UnsafeBufferPointer<UInt16> // expected-error {{cannot convert value of type 'UnsafeRawPointer' to type 'UnsafeBufferPointer<UInt16>' in coercion}}
141-
// expected-error@-1 {{cannot convert value of type 'UnsafeBufferPointer<UInt16>' to expected argument type 'UnsafeMutableRawPointer'}}
145+
array.withUnsafeBufferPointer {
146+
_ = UnsafeRawPointer($0) as UnsafeBufferPointer<UInt16> // expected-error {{cannot convert value of type 'UnsafeRawPointer' to type 'UnsafeBufferPointer<UInt16>' in coercion}}
147+
// expected-error@-1 {{cannot convert value of type 'UnsafeBufferPointer<UInt16>' to expected argument type 'UnsafeMutableRawPointer'}}
148+
}
142149
}
150+
do {
151+
func f1(_ u: Int) -> String {} // expected-note {{found this candidate}} expected-note {{candidate expects value of type 'Int' for parameter #1 (got 'Double')}}
152+
func f1(_ u: String) -> Double {} // expected-note {{found this candidate}} expected-note {{candidate expects value of type 'String' for parameter #1 (got 'Double')}}
153+
func f2(_ u: Int) {}
143154

144-
func SR12689_1(_ u: Int) -> String { "" } // expected-note {{found this candidate}} expected-note {{candidate expects value of type 'Int' for parameter #1 (got 'Double')}}
145-
func SR12689_1(_ u: String) -> Double { 0 } // expected-note {{found this candidate}} expected-note {{candidate expects value of type 'String' for parameter #1 (got 'Double')}}
146-
func SR12689_2(_ u: Int) {}
147-
148-
SR12689_2(SR12689_1(1 as Double)) // expected-error {{no exact matches in call to global function 'SR12689_1'}}
149-
SR12689_1(1 as Double) as Int // expected-error {{no exact matches in call to global function 'SR12689_1'}}
150-
151-
// Ambiguous OverloadRefExpr
152-
func SR12689_O(_ p: Int) {} // expected-note {{found candidate with type '(Int) -> ()'}}
153-
func SR12689_O(_ p: Double) {} // expected-note {{found candidate with type '(Double) -> ()'}}
154-
func SR12689_3(_ param: (String)-> Void) {}
155+
f2(f1(1 as Double)) // expected-error {{no exact matches in call to local function 'f1'}}
156+
f1(1 as Double) as Int // expected-error {{no exact matches in call to local function 'f1'}}
157+
}
158+
do {
159+
// Ambiguous OverloadRefExpr
160+
func f1(_ p: Int) {} // expected-note {{found candidate with type '(Int) -> ()'}}
161+
func f1(_ p: Double) {} // expected-note {{found candidate with type '(Double) -> ()'}}
162+
func f2(_ param: (String)-> Void) {}
155163

156-
SR12689_3(SR12689_O) // expected-error {{no 'SR12689_O' candidates produce the expected type '(String) -> Void' for parameter #0}}
164+
f2(f1) // expected-error {{no 'f1' candidates produce the expected type '(String) -> Void' for parameter #0}}
165+
}

test/Sema/enum_raw_representable.swift

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -168,47 +168,57 @@ func rdar32432253(_ condition: Bool = false) {
168168
// expected-error@-1 {{cannot convert value of type 'E_32431165' to expected argument type 'String'}} {{17-17=.rawValue}}
169169
}
170170

171-
func sr8150_helper1(_: Int) {}
172-
func sr8150_helper1(_: Double) {}
173-
174-
func sr8150_helper2(_: Double) {}
175-
func sr8150_helper2(_: Int) {}
176-
177-
func sr8150_helper3(_: Foo) {}
178-
func sr8150_helper3(_: Bar) {}
179-
180-
func sr8150_helper4(_: Bar) {}
181-
func sr8150_helper4(_: Foo) {}
182-
183-
func sr8150(bar: Bar) {
184-
sr8150_helper1(bar)
185-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{21-21=.rawValue}}
186-
sr8150_helper2(bar)
187-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{21-21=.rawValue}}
188-
sr8150_helper3(0.0)
189-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Bar'}} {{18-18=Bar(rawValue: }} {{21-21=) ?? <#default value#>}}
190-
sr8150_helper4(0.0)
191-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Bar'}} {{18-18=Bar(rawValue: }} {{21-21=) ?? <#default value#>}}
192-
}
171+
// https://github.com/apple/swift/issues/50682
172+
do {
173+
func helper1(_: Int) {}
174+
func helper1(_: Double) {}
193175

194-
class SR8150Box {
195-
var bar: Bar
196-
init(bar: Bar) { self.bar = bar }
197-
}
198-
// Bonus problem with mutable values being passed.
199-
func sr8150_mutable(obj: SR8150Box) {
200-
sr8150_helper1(obj.bar)
201-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{25-25=.rawValue}}
202-
203-
var bar = obj.bar
204-
sr8150_helper1(bar)
205-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{21-21=.rawValue}}
206-
207-
func test(_ opt: Bar?) {
208-
sr8150_helper1(opt)
209-
// expected-error@-1 {{cannot convert value of type 'Bar?' to expected argument type 'Double'}} {{23-23=?.rawValue ?? <#default value#>}}
210-
sr8150_helper1(opt ?? Bar.a)
211-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{20-20=(}} {{32-32=).rawValue}}
176+
func helper2(_: Double) {}
177+
func helper2(_: Int) {}
178+
179+
func helper3(_: Foo) {}
180+
func helper3(_: Bar) {}
181+
182+
func helper4(_: Bar) {}
183+
func helper4(_: Foo) {}
184+
185+
do {
186+
let bar: Bar
187+
188+
helper1(bar)
189+
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{16-16=.rawValue}}
190+
helper2(bar)
191+
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{16-16=.rawValue}}
192+
helper3(0.0)
193+
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Bar'}} {{13-13=Bar(rawValue: }} {{16-16=) ?? <#default value#>}}
194+
helper4(0.0)
195+
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Bar'}} {{13-13=Bar(rawValue: }} {{16-16=) ?? <#default value#>}}
196+
}
197+
198+
// Bonus problem with mutable values being passed.
199+
do {
200+
class Box {
201+
var bar: Bar
202+
init(bar: Bar) {}
203+
}
204+
205+
let box: Box
206+
207+
helper1(box.bar)
208+
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{20-20=.rawValue}}
209+
210+
var bar = box.bar
211+
helper1(bar)
212+
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{16-16=.rawValue}}
213+
}
214+
215+
do {
216+
let opt: Bar?
217+
218+
helper1(opt)
219+
// expected-error@-1 {{cannot convert value of type 'Bar?' to expected argument type 'Double'}} {{16-16=?.rawValue ?? <#default value#>}}
220+
helper1(opt ?? Bar.a)
221+
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{13-13=(}} {{25-25=).rawValue}}
212222
let _: Double? = opt
213223
// expected-error@-1 {{cannot convert value of type 'Bar?' to specified type 'Double?'}} {{25-25=?.rawValue}}
214224
}

0 commit comments

Comments
 (0)