Skip to content

Gardening: Migrate test suite to GH issues p. 8 #60641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 144 additions & 132 deletions test/Constraints/casts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ func ^^^ <T> (lhs: T?, rhs: @autoclosure () -> T?) -> T? { lhs! }

func ohno<T>(_ x: T) -> T? { nil }

// SR-12369: Make sure we don't drop the coercion constraint.
// https://github.com/apple/swift/issues/54803
// Make sure we don't drop the coercion constraint.
func test_coercions_with_overloaded_operator(str: String, optStr: String?, veryOptString: String????) {
_ = (str ?? "") as String // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}}
_ = (optStr ?? "") as String
Expand Down Expand Up @@ -357,15 +358,6 @@ func test_compatibility_coercions(_ arr: [Int], _ optArr: [Int]?, _ dict: [Strin
_ = [i: stringAnyDict] as! [String: Any]
}

// SR-13088
protocol JSON { }
protocol JSONLeaf: JSON {}
extension Int: JSONLeaf { }
extension Array: JSON where Element: JSON { }

protocol SR13035Error: Error {}
class ChildError: SR13035Error {}

protocol AnyC {
func foo()
}
Expand Down Expand Up @@ -393,48 +385,40 @@ enum ConcreteA: EventA {
}
}

protocol ProtocolP1 {}
protocol ProtocolQ1 {}
typealias Composition = ProtocolP1 & ProtocolQ1

protocol ProtocolP {}
protocol ProtocolQ {}

class ConcreteP: ProtocolP {}
class ConcreteQ: ProtocolQ {}
class ConcretePQ: ProtocolP, ProtocolQ {}
class ConcreteCPQ: ConcreteP, ProtocolQ {}
protocol JSON { }
protocol JSONLeaf: JSON {}
extension Int: JSONLeaf { }
extension Array: JSON where Element: JSON { }

class ConcreteP1: ProtocolP1 {}
class ConcretePQ1: ProtocolP1, ProtocolQ1 {}
protocol MyError: Error {}
class MyErrorClass: MyError {}

class ConcretePPQ1: ProtocolP, ProtocolP1, ProtocolQ1 {}
class NotConforms {}
struct StructNotComforms {}
final class NotConformsFinal {}
// https://github.com/apple/swift/issues/55534 (Umbrella issue)
func test_always_fail_casts() {

func tests_SR13088_false_positive_always_fail_casts() {
// SR-13081
// https://github.com/apple/swift/issues/55527
let x: JSON = [4] // [4]
_ = x as? [Any] // Ok

// SR-13035
func SR13035<SomeError: SR13035Error>(_ child: Result<String, ChildError>, _: Result<String, SomeError>) {
let _ = child as? Result<String, SomeError> // Ok
}

func SR13035_1<SomeError: SR13035Error, Child: ChildError>(_ child: Result<String, Child>, parent: Result<String, SomeError>) {
_ = child as? Result<String, SomeError> // Ok
// https://github.com/apple/swift/issues/55481
func f_55481<Parent: MyError, Child: MyErrorClass>(
_ parent: Result<String, Parent>,
_ childGeneric: Result<String, Child>,
_ childConcrete: Result<String, MyErrorClass>
) {
_ = childConcrete as? Result<String, Parent> // Ok
_ = childGeneric as? Result<String, Parent> // Ok
_ = parent as? Result<String, Child> // OK
}

// SR-11434 and SR-12321
// https://github.com/apple/swift/issues/53835
// https://github.com/apple/swift/issues/54751
func encodable(_ value: Encodable) {
_ = value as! [String : Encodable] // Ok
_ = value as? [String: Encodable] // Ok
}

// SR-13025
// https://github.com/apple/swift/issues/55470
func coordinate(_ event: AnyEvent, from c: AnyC) {
switch (event, c) {
case let container as Container<ConcreteA>: // OK
Expand All @@ -444,7 +428,7 @@ func tests_SR13088_false_positive_always_fail_casts() {
}
}

// SR-7187
// https://github.com/apple/swift/issues/49735
let a: [Any] = [String?.some("hello") as Any, String?.none as Any]
let b: [AnyObject] = [String?.some("hello") as AnyObject, String?.none as AnyObject]

Expand All @@ -453,7 +437,7 @@ func tests_SR13088_false_positive_always_fail_casts() {
_ = b is [String?] // Ok
_ = b as? [String?] as AnyObject // OK

// SR-6192
// https://github.com/apple/swift/issues/48744
let items = [String]()
let dict = [String: Any]()
let set = Set<String>()
Expand All @@ -472,6 +456,26 @@ func tests_SR13088_false_positive_always_fail_casts() {

}

protocol ProtocolP1 {}
protocol ProtocolQ1 {}
typealias Composition = ProtocolP1 & ProtocolQ1

protocol ProtocolP {}
protocol ProtocolQ {}

class ConcreteP: ProtocolP {}
class ConcreteQ: ProtocolQ {}
class ConcretePQ: ProtocolP, ProtocolQ {}
class ConcreteCPQ: ConcreteP, ProtocolQ {}

class ConcreteP1: ProtocolP1 {}
class ConcretePQ1: ProtocolP1, ProtocolQ1 {}

class ConcretePPQ1: ProtocolP, ProtocolP1, ProtocolQ1 {}
class NotConforms {}
struct StructNotComforms {}
final class NotConformsFinal {}

// Protocol composition
func protocol_composition(_ c: ProtocolP & ProtocolQ, _ c1: ProtocolP & Composition) {
_ = c as? ConcretePQ // Ok
Expand All @@ -489,72 +493,76 @@ func protocol_composition(_ c: ProtocolP & ProtocolQ, _ c1: ProtocolP & Composit
_ = c1 as? NotConformsFinal // expected-warning {{cast from 'any ProtocolP & Composition' (aka 'any ProtocolP & ProtocolP1 & ProtocolQ1') to unrelated type 'NotConformsFinal' always fails}}
}

// SR-13899
class SR13899_Base {}
class SR13899_Derived: SR13899_Base {}

protocol SR13899_P {}
class SR13899_A: SR13899_P {}

typealias DA = SR13899_Derived
typealias BA = SR13899_Base
typealias ClosureType = (SR13899_Derived) -> Void

let blockp = { (_: SR13899_A) in }
let block = { (_: SR13899_Base) in }
let derived = { (_: SR13899_Derived) in }

let blockalias = { (_: BA) in }
let derivedalias = { (_: DA) in }

let _ = block is ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}
let _ = blockalias is (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(SR13899_Base) -> ()') to '(SR13899_Derived) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-22=as}}
let _ = block is (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}
let _ = block is (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}

let _ = block as! ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
let _ = blockalias as! (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(SR13899_Base) -> ()') to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-23=as}}
let _ = block as! (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
let _ = block as! (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}

let _ = block as? ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
let _ = blockalias as? (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(SR13899_Base) -> ()') to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-23=as}}
let _ = block as? (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
let _ = block as? (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}


let _ = derived is (SR13899_Base) -> Void // expected-warning{{always fails}}
let _ = blockp is (SR13899_P) -> Void // expected-warning{{always fails}}

// Types are trivially equal.
let _ = block is (SR13899_Base) -> Void // expected-warning{{'is' test is always true}}
let _ = block is (SR13899_Base) throws -> Void // expected-warning{{'is' test is always true}}
let _ = derivedalias is (SR13899_Derived) -> Void // expected-warning{{'is' test is always true}}
let _ = derivedalias is (SR13899_Derived) throws -> Void // expected-warning{{'is' test is always true}}
let _ = derived is (SR13899_Derived) -> Void // expected-warning{{'is' test is always true}}
let _ = derived is (SR13899_Derived) throws -> Void // expected-warning{{'is' test is always true}}
let _ = blockp is (SR13899_A) -> Void //expected-warning{{'is' test is always true}}
let _ = blockp is (SR13899_A) throws -> Void //expected-warning{{'is' test is always true}}
// https://github.com/apple/swift/issues/56297

class C1_56297_Base {}
class C1_56297_Sub: C1_56297_Base {}

protocol P_56297 {}
class C2_56297: P_56297 {}

do {
typealias DA = C1_56297_Sub
typealias BA = C1_56297_Base
typealias ClosureType = (C1_56297_Sub) -> Void

let blockp = { (_: C2_56297) in }
let block = { (_: C1_56297_Base) in }
let derived = { (_: C1_56297_Sub) in }

let blockalias = { (_: BA) in }
let derivedalias = { (_: DA) in }

let _ = block is ClosureType // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to 'ClosureType' (aka '(C1_56297_Sub) -> ()') is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}
let _ = blockalias is (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(C1_56297_Base) -> ()') to '(C1_56297_Sub) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-24=as}}
let _ = block is (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}
let _ = block is (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; 'is' test always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}

let _ = block as! ClosureType // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to 'ClosureType' (aka '(C1_56297_Sub) -> ()') is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
let _ = blockalias as! (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(C1_56297_Base) -> ()') to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-25=as}}
let _ = block as! (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
let _ = block as! (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}

let _ = block as? ClosureType // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to 'ClosureType' (aka '(C1_56297_Sub) -> ()') is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
let _ = blockalias as? (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(BA) -> ()' (aka '(C1_56297_Base) -> ()') to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-25=as}}
let _ = block as? (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
let _ = block as? (C1_56297_Sub) -> Void // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to '(C1_56297_Sub) -> Void' is not supported; cast always fails}}
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}


let _ = derived is (C1_56297_Base) -> Void // expected-warning{{always fails}}
let _ = blockp is (P_56297) -> Void // expected-warning{{always fails}}

// Types are trivially equal.
let _ = block is (C1_56297_Base) -> Void // expected-warning{{'is' test is always true}}
let _ = block is (C1_56297_Base) throws -> Void // expected-warning{{'is' test is always true}}
let _ = derivedalias is (C1_56297_Sub) -> Void // expected-warning{{'is' test is always true}}
let _ = derivedalias is (C1_56297_Sub) throws -> Void // expected-warning{{'is' test is always true}}
let _ = derived is (C1_56297_Sub) -> Void // expected-warning{{'is' test is always true}}
let _ = derived is (C1_56297_Sub) throws -> Void // expected-warning{{'is' test is always true}}
let _ = blockp is (C2_56297) -> Void //expected-warning{{'is' test is always true}}
let _ = blockp is (C2_56297) throws -> Void //expected-warning{{'is' test is always true}}
}

protocol PP1 { }
protocol PP2: PP1 { }
extension Optional: PP1 where Wrapped == PP2 { }

nil is PP1 // expected-error {{'nil' requires a contextual type}}

// SR-15039
// https://github.com/apple/swift/issues/57366

enum ChangeType<T> {
case initial(T)
case delta(previous: T, next: T)
Expand All @@ -568,7 +576,8 @@ extension ChangeType where T == String? {
var bar: String? { self.delta?.next }
}

// SR-15038
// https://github.com/apple/swift/issues/57365

protocol ExperimentDeserializable {
static func deserializeExperiment(_ value: Any) -> Self?
}
Expand Down Expand Up @@ -633,45 +642,48 @@ func decodeStringOrIntDictionary<T: FixedWidthInteger>() -> [Int: T] {
}


// SR-15281
struct SR15281_A { }
struct SR15281_B {
init(a: SR15281_A) { }
}
// https://github.com/apple/swift/issues/57603
do {
struct S1 { }
struct S2 {
init(a: S1) { }
}

struct SR15281_S {
var a: SR15281_A? = SR15281_A()
struct S3 {
var a: S1? = S1()

var b: SR15281_B {
a.flatMap(SR15281_B.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_B?' to return type 'SR15281_B'}} {{34-34=!}}
}
var b: S2 {
a.flatMap(S2.init(a:))
// expected-error@-1 {{cannot convert return expression of type 'S2?' to return type 'S2'}} {{29-29=!}}
}

var b1: SR15281_B {
a.flatMap(SR15281_B.init(a:)) as! SR15281_B
// expected-warning@-1 {{forced cast from 'SR15281_B?' to 'SR15281_B' only unwraps optionals; did you mean to use '!'?}} {{34-34=!}} {{34-48=}}
var b1: S2 {
a.flatMap(S2.init(a:)) as! S2
// expected-warning@-1 {{forced cast from 'S2?' to 'S2' only unwraps optionals; did you mean to use '!'?}} {{29-29=!}} {{29-36=}}
}
}
}

class SR15281_AC {}
class SR15281_BC {
init(a: SR15281_AC) { }
}
class SR15281_CC: SR15281_BC {}
class C1 {}
class C2 {
init(a: C1) { }
}
class C3: C2 {}

struct SR15281_SC {
var a: SR15281_AC? = SR15281_AC()
struct S4 {
var a: C1? = C1()

var b: SR15281_BC {
a.flatMap(SR15281_BC.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_BC?' to return type 'SR15281_BC'}} {{35-35=!}}
}
var b: C2 {
a.flatMap(C2.init(a:)) // expected-error{{cannot convert return expression of type 'C2?' to return type 'C2'}} {{29-29=!}}
}

var c: SR15281_BC {
a.flatMap(SR15281_CC.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_CC?' to return type 'SR15281_BC'}} {{35-35=!}}
var c: C2 {
a.flatMap(C3.init(a:)) // expected-error{{cannot convert return expression of type 'C3?' to return type 'C2'}} {{29-29=!}}
}
}
}

// SR-15562
func test_SR_15562() {
// https://github.com/apple/swift/issues/57865
do {
let foo: [Int: Int] = [:]
let bar = [1, 2, 3, 4]

Expand All @@ -681,17 +693,17 @@ func test_SR_15562() {
}
}

// SR-16058
// https://github.com/apple/swift/issues/58319
extension Dictionary {
func SR16058(_: Key) -> Value?? { nil }
func f_58319(_: Key) -> Value?? { nil }
}
func SR_16058_tests() {
do {
let dict: [Int: String?] = [:]
let foo: Int? = 1
let _: String? = foo.flatMap { dict[$0] } as? String // OK

// More than one optionality wrapping
let _: String? = foo.flatMap { dict.SR16058(_: $0) } as? String // OK
let _: String? = foo.flatMap { dict.f_58319(_: $0) } as? String // OK
}

// https://github.com/apple/swift/issues/59405
Expand Down
Loading