Skip to content

Commit b793415

Browse files
committed
[TypeChecker] NFC: Adjust test-cases improved by optional unwrap fix
1 parent 595f85f commit b793415

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

test/ClangImporter/cf.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func testOutParametersBad() {
119119

120120
let power: CCPowerSupply?
121121
CCRefrigeratorGetPowerSupplyIndirect(0, power) // expected-error {{cannot convert value of type 'Int' to expected argument type 'CCRefrigerator?'}}
122-
// expected-error@-1 {{cannot convert value of type 'CCPowerSupply?' to expected argument type 'AutoreleasingUnsafeMutablePointer<CCPowerSupply?>'}}
123122

124123
let item: CCItem?
125124
CCRefrigeratorGetItemUnaudited(0, 0, item) // expected-error {{cannot convert value of type 'Int' to expected argument type 'CCRefrigerator?'}}

test/Constraints/iuo.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ func conditionalDowncastToOptional(b: B?) -> D? {
210210
}
211211

212212
func conditionalDowncastToObject(b: B?) -> D {
213-
return b as? D! // expected-error {{cannot convert return expression of type 'D??' to return type 'D'}}
214-
// expected-warning@-1 {{using '!' here is deprecated and will be removed in a future release}}
213+
return b as? D! // expected-error {{value of optional type 'D?' must be unwrapped to a value of type 'D'}}
214+
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
215+
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
216+
// expected-warning@-3 {{using '!' here is deprecated and will be removed in a future release}}
215217
}
216218

217219
// Ensure that we select the overload that does *not* involve forcing an IUO.

test/Parse/try.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ struct ThingProducer {
236236
}
237237

238238
let optProducer: ThingProducer? = ThingProducer()
239-
let _: Int? = try? optProducer?.produceInt() // expected-error {{value of optional type 'Int??' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
239+
// In Swift 4 mode try? always adds a new level of optionality so suggesting `try!` doesn't really help in these examples.
240+
let _: Int? = try? optProducer?.produceInt() // expected-error {{cannot convert value of type 'Int??' to specified type 'Int?'}}
240241
let _: Int = try? optProducer?.produceInt() // expected-error {{cannot convert value of type 'Int??' to specified type 'Int'}}
241242
let _: String = try? optProducer?.produceInt() // expected-error {{cannot convert value of type 'Int??' to specified type 'String'}}
242243
let _: Int?? = try? optProducer?.produceInt() // good
243244

244-
let _: Int? = try? optProducer?.produceIntNoThrowing() // expected-error {{value of optional type 'Int??' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
245+
let _: Int? = try? optProducer?.produceIntNoThrowing() // expected-error {{cannot convert value of type 'Int??' to specified type 'Int?'}}
246+
// expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}
245247
let _: Int?? = try? optProducer?.produceIntNoThrowing() // expected-warning {{no calls to throwing functions occur within 'try' expression}}
246248

247249
let _: Int? = (try? optProducer?.produceAny()) as? Int // good
@@ -253,7 +255,7 @@ let _: String = try? optProducer?.produceDoubleOptionalInt() // expected-error {
253255

254256
let producer = ThingProducer()
255257

256-
let _: Int = try? producer.produceDoubleOptionalInt() // expected-error {{cannot convert value of type 'Int???' to specified type 'Int'}}
258+
let _: Int = try? producer.produceDoubleOptionalInt() // expected-error {{value of optional type 'Int???' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
257259
let _: Int? = try? producer.produceDoubleOptionalInt() // expected-error {{value of optional type 'Int???' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
258260
let _: Int?? = try? producer.produceDoubleOptionalInt() // expected-error {{value of optional type 'Int???' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
259261
let _: Int??? = try? producer.produceDoubleOptionalInt() // good

0 commit comments

Comments
 (0)