Skip to content

Commit e51ef47

Browse files
committed
Gardening: Migrate test suite to GH issues: Constraints (5/5)
1 parent b0fb7c5 commit e51ef47

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
@@ -357,15 +358,6 @@ func test_compatibility_coercions(_ arr: [Int], _ optArr: [Int]?, _ dict: [Strin
357358
_ = [i: stringAnyDict] as! [String: Any]
358359
}
359360

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

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

408-
class ConcreteP1: ProtocolP1 {}
409-
class ConcretePQ1: ProtocolP1, ProtocolQ1 {}
393+
protocol MyError: Error {}
394+
class MyErrorClass: MyError {}
410395

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

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

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

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

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

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

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

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

473457
}
474458

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

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

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

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

557-
// SR-15039
564+
// https://github.com/apple/swift/issues/57366
565+
558566
enum ChangeType<T> {
559567
case initial(T)
560568
case delta(previous: T, next: T)
@@ -568,7 +576,8 @@ extension ChangeType where T == String? {
568576
var bar: String? { self.delta?.next }
569577
}
570578

571-
// SR-15038
579+
// https://github.com/apple/swift/issues/57365
580+
572581
protocol ExperimentDeserializable {
573582
static func deserializeExperiment(_ value: Any) -> Self?
574583
}
@@ -633,45 +642,48 @@ func decodeStringOrIntDictionary<T: FixedWidthInteger>() -> [Int: T] {
633642
}
634643

635644

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

642-
struct SR15281_S {
643-
var a: SR15281_A? = SR15281_A()
652+
struct S3 {
653+
var a: S1? = S1()
644654

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

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

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

661-
struct SR15281_SC {
662-
var a: SR15281_AC? = SR15281_AC()
672+
struct S4 {
673+
var a: C1? = C1()
663674

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

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

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

@@ -681,17 +693,17 @@ func test_SR_15562() {
681693
}
682694
}
683695

684-
// SR-16058
696+
// https://github.com/apple/swift/issues/58319
685697
extension Dictionary {
686-
func SR16058(_: Key) -> Value?? { nil }
698+
func f_58319(_: Key) -> Value?? { nil }
687699
}
688-
func SR_16058_tests() {
700+
do {
689701
let dict: [Int: String?] = [:]
690702
let foo: Int? = 1
691703
let _: String? = foo.flatMap { dict[$0] } as? String // OK
692704

693705
// More than one optionality wrapping
694-
let _: String? = foo.flatMap { dict.SR16058(_: $0) } as? String // OK
706+
let _: String? = foo.flatMap { dict.f_58319(_: $0) } as? String // OK
695707
}
696708

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

0 commit comments

Comments
 (0)