Skip to content

Commit dd627b4

Browse files
Merge pull request #60641 from AnthonyLatsis/migrate-test-suite-to-gh-issues-8
2 parents 599afbf + e51ef47 commit dd627b4

File tree

2 files changed

+280
-246
lines changed

2 files changed

+280
-246
lines changed

test/Constraints/casts.swift

Lines changed: 144 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ func ^^^ <T> (lhs: T?, rhs: @autoclosure () -> T?) -> T? { lhs! }
245245

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

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

361-
// SR-13088
362-
protocol JSON { }
363-
protocol JSONLeaf: JSON {}
364-
extension Int: JSONLeaf { }
365-
extension Array: JSON where Element: JSON { }
366-
367-
protocol SR13035Error: Error {}
368-
class ChildError: SR13035Error {}
369-
370362
protocol AnyC {
371363
func foo()
372364
}
@@ -394,48 +386,40 @@ enum ConcreteA: EventA {
394386
}
395387
}
396388

397-
protocol ProtocolP1 {}
398-
protocol ProtocolQ1 {}
399-
typealias Composition = ProtocolP1 & ProtocolQ1
400-
401-
protocol ProtocolP {}
402-
protocol ProtocolQ {}
403-
404-
class ConcreteP: ProtocolP {}
405-
class ConcreteQ: ProtocolQ {}
406-
class ConcretePQ: ProtocolP, ProtocolQ {}
407-
class ConcreteCPQ: ConcreteP, ProtocolQ {}
389+
protocol JSON { }
390+
protocol JSONLeaf: JSON {}
391+
extension Int: JSONLeaf { }
392+
extension Array: JSON where Element: JSON { }
408393

409-
class ConcreteP1: ProtocolP1 {}
410-
class ConcretePQ1: ProtocolP1, ProtocolQ1 {}
394+
protocol MyError: Error {}
395+
class MyErrorClass: MyError {}
411396

412-
class ConcretePPQ1: ProtocolP, ProtocolP1, ProtocolQ1 {}
413-
class NotConforms {}
414-
struct StructNotComforms {}
415-
final class NotConformsFinal {}
397+
// https://github.com/apple/swift/issues/55534 (Umbrella issue)
398+
func test_always_fail_casts() {
416399

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

422-
// SR-13035
423-
func SR13035<SomeError: SR13035Error>(_ child: Result<String, ChildError>, _: Result<String, SomeError>) {
424-
let _ = child as? Result<String, SomeError> // Ok
425-
}
426-
427-
func SR13035_1<SomeError: SR13035Error, Child: ChildError>(_ child: Result<String, Child>, parent: Result<String, SomeError>) {
428-
_ = child as? Result<String, SomeError> // Ok
404+
// https://github.com/apple/swift/issues/55481
405+
func f_55481<Parent: MyError, Child: MyErrorClass>(
406+
_ parent: Result<String, Parent>,
407+
_ childGeneric: Result<String, Child>,
408+
_ childConcrete: Result<String, MyErrorClass>
409+
) {
410+
_ = childConcrete as? Result<String, Parent> // Ok
411+
_ = childGeneric as? Result<String, Parent> // Ok
429412
_ = parent as? Result<String, Child> // OK
430413
}
431414

432-
// SR-11434 and SR-12321
415+
// https://github.com/apple/swift/issues/53835
416+
// https://github.com/apple/swift/issues/54751
433417
func encodable(_ value: Encodable) {
434418
_ = value as! [String : Encodable] // Ok
435419
_ = value as? [String: Encodable] // Ok
436420
}
437421

438-
// SR-13025
422+
// https://github.com/apple/swift/issues/55470
439423
func coordinate(_ event: AnyEvent, from c: AnyC) {
440424
switch (event, c) {
441425
case let container as Container<ConcreteA>: // OK
@@ -445,7 +429,7 @@ func tests_SR13088_false_positive_always_fail_casts() {
445429
}
446430
}
447431

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

@@ -454,7 +438,7 @@ func tests_SR13088_false_positive_always_fail_casts() {
454438
_ = b is [String?] // Ok
455439
_ = b as? [String?] as AnyObject // OK
456440

457-
// SR-6192
441+
// https://github.com/apple/swift/issues/48744
458442
let items = [String]()
459443
let dict = [String: Any]()
460444
let set = Set<String>()
@@ -473,6 +457,26 @@ func tests_SR13088_false_positive_always_fail_casts() {
473457

474458
}
475459

460+
protocol ProtocolP1 {}
461+
protocol ProtocolQ1 {}
462+
typealias Composition = ProtocolP1 & ProtocolQ1
463+
464+
protocol ProtocolP {}
465+
protocol ProtocolQ {}
466+
467+
class ConcreteP: ProtocolP {}
468+
class ConcreteQ: ProtocolQ {}
469+
class ConcretePQ: ProtocolP, ProtocolQ {}
470+
class ConcreteCPQ: ConcreteP, ProtocolQ {}
471+
472+
class ConcreteP1: ProtocolP1 {}
473+
class ConcretePQ1: ProtocolP1, ProtocolQ1 {}
474+
475+
class ConcretePPQ1: ProtocolP, ProtocolP1, ProtocolQ1 {}
476+
class NotConforms {}
477+
struct StructNotComforms {}
478+
final class NotConformsFinal {}
479+
476480
// Protocol composition
477481
func protocol_composition(_ c: ProtocolP & ProtocolQ, _ c1: ProtocolP & Composition) {
478482
_ = c as? ConcretePQ // Ok
@@ -490,72 +494,76 @@ func protocol_composition(_ c: ProtocolP & ProtocolQ, _ c1: ProtocolP & Composit
490494
_ = c1 as? NotConformsFinal // expected-warning {{cast from 'any ProtocolP & Composition' (aka 'any ProtocolP & ProtocolP1 & ProtocolQ1') to unrelated type 'NotConformsFinal' always fails}}
491495
}
492496

493-
// SR-13899
494-
class SR13899_Base {}
495-
class SR13899_Derived: SR13899_Base {}
496-
497-
protocol SR13899_P {}
498-
class SR13899_A: SR13899_P {}
499-
500-
typealias DA = SR13899_Derived
501-
typealias BA = SR13899_Base
502-
typealias ClosureType = (SR13899_Derived) -> Void
503-
504-
let blockp = { (_: SR13899_A) in }
505-
let block = { (_: SR13899_Base) in }
506-
let derived = { (_: SR13899_Derived) in }
507-
508-
let blockalias = { (_: BA) in }
509-
let derivedalias = { (_: DA) in }
510-
511-
let _ = block is ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; 'is' test always fails}}
512-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}
513-
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}}
514-
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-22=as}}
515-
let _ = block is (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; 'is' test always fails}}
516-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}
517-
let _ = block is (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; 'is' test always fails}}
518-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-17=as}}
519-
520-
let _ = block as! ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; cast always fails}}
521-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
522-
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}}
523-
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-23=as}}
524-
let _ = block as! (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
525-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
526-
let _ = block as! (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
527-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
528-
529-
let _ = block as? ClosureType // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to 'ClosureType' (aka '(SR13899_Derived) -> ()') is not supported; cast always fails}}
530-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
531-
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}}
532-
// expected-note@-1 {{consider using 'as' coercion instead}} {{20-23=as}}
533-
let _ = block as? (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
534-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
535-
let _ = block as? (SR13899_Derived) -> Void // expected-warning{{runtime conversion from '(SR13899_Base) -> ()' to '(SR13899_Derived) -> Void' is not supported; cast always fails}}
536-
// expected-note@-1 {{consider using 'as' coercion instead}} {{15-18=as}}
537-
538-
539-
let _ = derived is (SR13899_Base) -> Void // expected-warning{{always fails}}
540-
let _ = blockp is (SR13899_P) -> Void // expected-warning{{always fails}}
541-
542-
// Types are trivially equal.
543-
let _ = block is (SR13899_Base) -> Void // expected-warning{{'is' test is always true}}
544-
let _ = block is (SR13899_Base) throws -> Void // expected-warning{{'is' test is always true}}
545-
let _ = derivedalias is (SR13899_Derived) -> Void // expected-warning{{'is' test is always true}}
546-
let _ = derivedalias is (SR13899_Derived) throws -> Void // expected-warning{{'is' test is always true}}
547-
let _ = derived is (SR13899_Derived) -> Void // expected-warning{{'is' test is always true}}
548-
let _ = derived is (SR13899_Derived) throws -> Void // expected-warning{{'is' test is always true}}
549-
let _ = blockp is (SR13899_A) -> Void //expected-warning{{'is' test is always true}}
550-
let _ = blockp is (SR13899_A) throws -> Void //expected-warning{{'is' test is always true}}
497+
// https://github.com/apple/swift/issues/56297
498+
499+
class C1_56297_Base {}
500+
class C1_56297_Sub: C1_56297_Base {}
501+
502+
protocol P_56297 {}
503+
class C2_56297: P_56297 {}
504+
505+
do {
506+
typealias DA = C1_56297_Sub
507+
typealias BA = C1_56297_Base
508+
typealias ClosureType = (C1_56297_Sub) -> Void
509+
510+
let blockp = { (_: C2_56297) in }
511+
let block = { (_: C1_56297_Base) in }
512+
let derived = { (_: C1_56297_Sub) in }
513+
514+
let blockalias = { (_: BA) in }
515+
let derivedalias = { (_: DA) in }
516+
517+
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}}
518+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}
519+
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}}
520+
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-24=as}}
521+
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}}
522+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}
523+
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}}
524+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-19=as}}
525+
526+
let _ = block as! ClosureType // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to 'ClosureType' (aka '(C1_56297_Sub) -> ()') is not supported; cast always fails}}
527+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
528+
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}}
529+
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-25=as}}
530+
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}}
531+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
532+
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}}
533+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
534+
535+
let _ = block as? ClosureType // expected-warning{{runtime conversion from '(C1_56297_Base) -> ()' to 'ClosureType' (aka '(C1_56297_Sub) -> ()') is not supported; cast always fails}}
536+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
537+
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}}
538+
// expected-note@-1 {{consider using 'as' coercion instead}} {{22-25=as}}
539+
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}}
540+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
541+
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}}
542+
// expected-note@-1 {{consider using 'as' coercion instead}} {{17-20=as}}
543+
544+
545+
let _ = derived is (C1_56297_Base) -> Void // expected-warning{{always fails}}
546+
let _ = blockp is (P_56297) -> Void // expected-warning{{always fails}}
547+
548+
// Types are trivially equal.
549+
let _ = block is (C1_56297_Base) -> Void // expected-warning{{'is' test is always true}}
550+
let _ = block is (C1_56297_Base) throws -> Void // expected-warning{{'is' test is always true}}
551+
let _ = derivedalias is (C1_56297_Sub) -> Void // expected-warning{{'is' test is always true}}
552+
let _ = derivedalias is (C1_56297_Sub) throws -> Void // expected-warning{{'is' test is always true}}
553+
let _ = derived is (C1_56297_Sub) -> Void // expected-warning{{'is' test is always true}}
554+
let _ = derived is (C1_56297_Sub) throws -> Void // expected-warning{{'is' test is always true}}
555+
let _ = blockp is (C2_56297) -> Void //expected-warning{{'is' test is always true}}
556+
let _ = blockp is (C2_56297) throws -> Void //expected-warning{{'is' test is always true}}
557+
}
551558

552559
protocol PP1 { }
553560
protocol PP2: PP1 { }
554561
extension Optional: PP1 where Wrapped == PP2 { }
555562

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

558-
// SR-15039
565+
// https://github.com/apple/swift/issues/57366
566+
559567
enum ChangeType<T> {
560568
case initial(T)
561569
case delta(previous: T, next: T)
@@ -569,7 +577,8 @@ extension ChangeType where T == String? {
569577
var bar: String? { self.delta?.next }
570578
}
571579

572-
// SR-15038
580+
// https://github.com/apple/swift/issues/57365
581+
573582
protocol ExperimentDeserializable {
574583
static func deserializeExperiment(_ value: Any) -> Self?
575584
}
@@ -634,45 +643,48 @@ func decodeStringOrIntDictionary<T: FixedWidthInteger>() -> [Int: T] {
634643
}
635644

636645

637-
// SR-15281
638-
struct SR15281_A { }
639-
struct SR15281_B {
640-
init(a: SR15281_A) { }
641-
}
646+
// https://github.com/apple/swift/issues/57603
647+
do {
648+
struct S1 { }
649+
struct S2 {
650+
init(a: S1) { }
651+
}
642652

643-
struct SR15281_S {
644-
var a: SR15281_A? = SR15281_A()
653+
struct S3 {
654+
var a: S1? = S1()
645655

646-
var b: SR15281_B {
647-
a.flatMap(SR15281_B.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_B?' to return type 'SR15281_B'}} {{34-34=!}}
648-
}
656+
var b: S2 {
657+
a.flatMap(S2.init(a:))
658+
// expected-error@-1 {{cannot convert return expression of type 'S2?' to return type 'S2'}} {{29-29=!}}
659+
}
649660

650-
var b1: SR15281_B {
651-
a.flatMap(SR15281_B.init(a:)) as! SR15281_B
652-
// expected-warning@-1 {{forced cast from 'SR15281_B?' to 'SR15281_B' only unwraps optionals; did you mean to use '!'?}} {{34-34=!}} {{34-48=}}
661+
var b1: S2 {
662+
a.flatMap(S2.init(a:)) as! S2
663+
// expected-warning@-1 {{forced cast from 'S2?' to 'S2' only unwraps optionals; did you mean to use '!'?}} {{29-29=!}} {{29-36=}}
664+
}
653665
}
654-
}
655666

656-
class SR15281_AC {}
657-
class SR15281_BC {
658-
init(a: SR15281_AC) { }
659-
}
660-
class SR15281_CC: SR15281_BC {}
667+
class C1 {}
668+
class C2 {
669+
init(a: C1) { }
670+
}
671+
class C3: C2 {}
661672

662-
struct SR15281_SC {
663-
var a: SR15281_AC? = SR15281_AC()
673+
struct S4 {
674+
var a: C1? = C1()
664675

665-
var b: SR15281_BC {
666-
a.flatMap(SR15281_BC.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_BC?' to return type 'SR15281_BC'}} {{35-35=!}}
667-
}
676+
var b: C2 {
677+
a.flatMap(C2.init(a:)) // expected-error{{cannot convert return expression of type 'C2?' to return type 'C2'}} {{29-29=!}}
678+
}
668679

669-
var c: SR15281_BC {
670-
a.flatMap(SR15281_CC.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_CC?' to return type 'SR15281_BC'}} {{35-35=!}}
680+
var c: C2 {
681+
a.flatMap(C3.init(a:)) // expected-error{{cannot convert return expression of type 'C3?' to return type 'C2'}} {{29-29=!}}
682+
}
671683
}
672684
}
673685

674-
// SR-15562
675-
func test_SR_15562() {
686+
// https://github.com/apple/swift/issues/57865
687+
do {
676688
let foo: [Int: Int] = [:]
677689
let bar = [1, 2, 3, 4]
678690

@@ -682,17 +694,17 @@ func test_SR_15562() {
682694
}
683695
}
684696

685-
// SR-16058
697+
// https://github.com/apple/swift/issues/58319
686698
extension Dictionary {
687-
func SR16058(_: Key) -> Value?? { nil }
699+
func f_58319(_: Key) -> Value?? { nil }
688700
}
689-
func SR_16058_tests() {
701+
do {
690702
let dict: [Int: String?] = [:]
691703
let foo: Int? = 1
692704
let _: String? = foo.flatMap { dict[$0] } as? String // OK
693705

694706
// More than one optionality wrapping
695-
let _: String? = foo.flatMap { dict.SR16058(_: $0) } as? String // OK
707+
let _: String? = foo.flatMap { dict.f_58319(_: $0) } as? String // OK
696708
}
697709

698710
// https://github.com/apple/swift/issues/59405

0 commit comments

Comments
 (0)