@@ -657,6 +657,115 @@ func test_as_pattern(_ y : BaseClass) -> DerivedClass {
657
657
// CHECK-NEXT: return [[RESULT]] : $DerivedClass
658
658
return result
659
659
}
660
+
661
+ // https://github.com/apple/swift/issues/56139
662
+
663
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements30test_as_pattern_array_downcastyySayAA9BaseClassCGF : $@convention(thin) (@guaranteed Array<BaseClass>) -> () {
664
+ func test_as_pattern_array_downcast( _ arr: [ BaseClass ] ) {
665
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
666
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
667
+ // CHECK-NEXT: switch_enum [[RESULT]]
668
+ if case _ as [ DerivedClass ] = arr { }
669
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
670
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
671
+ // CHECK-NEXT: switch_enum [[RESULT]]
672
+ guard case _ as [ DerivedClass ] = arr else { }
673
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
674
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
675
+ // CHECK-NEXT: switch_enum [[RESULT]]
676
+ while case _ as [ DerivedClass ] = arr { }
677
+ }
678
+ // CHECK: } // end sil function '$s10statements30test_as_pattern_array_downcastyySayAA9BaseClassCGF'
679
+
680
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements35test_as_pattern_dictionary_downcastyySDySSAA9BaseClassCGF : $@convention(thin) (@guaranteed Dictionary<String, BaseClass>) -> () {
681
+ func test_as_pattern_dictionary_downcast( _ dict: Dictionary < String , BaseClass > ) {
682
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
683
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
684
+ // CHECK-NEXT: switch_enum [[RESULT]]
685
+ if case _ as [ String : DerivedClass ] = dict { }
686
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
687
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
688
+ // CHECK-NEXT: switch_enum [[RESULT]]
689
+ guard case _ as [ String : DerivedClass ] = dict else { }
690
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
691
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
692
+ // CHECK-NEXT: switch_enum [[RESULT]]
693
+ while case _ as [ String : DerivedClass ] = dict { }
694
+ }
695
+ // CHECK: } // end sil function '$s10statements35test_as_pattern_dictionary_downcastyySDySSAA9BaseClassCGF'
696
+
697
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements28test_as_pattern_set_downcastyyShyxGSHRzlF : $@convention(thin) <T where T : Hashable> (@guaranteed Set<T>) -> () {
698
+ func test_as_pattern_set_downcast< T: Hashable > ( _ set: Set < T > ) {
699
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
700
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Bool>
701
+ // CHECK-NEXT: switch_enum [[RESULT]]
702
+ if case let t as Set < Bool > = set { }
703
+ // FIXME: Get rid of these warnings when https://github.com/apple/swift/issues/60808 is fixed
704
+ // expected-warning@-2 {{immutable value 't' was never used; consider replacing with '_' or removing it}}
705
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
706
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Bool>
707
+ // CHECK-NEXT: switch_enum [[RESULT]]
708
+ guard case let t as Set < Bool > = set else { }
709
+ // expected-warning@-1 {{immutable value 't' was never used; consider replacing with '_' or removing it}}
710
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
711
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Bool>
712
+ // CHECK-NEXT: switch_enum [[RESULT]]
713
+ while case let t as Set < Bool > = set { }
714
+ // expected-warning@-1 {{immutable value 't' was never used; consider replacing with '_' or removing it}}
715
+ }
716
+ // CHECK: } // end sil function '$s10statements28test_as_pattern_set_downcastyyShyxGSHRzlF'
717
+
718
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements31test_isa_pattern_array_downcastyySayAA9BaseClassCGF : $@convention(thin) (@guaranteed Array<BaseClass>) -> () {
719
+ func test_isa_pattern_array_downcast( _ arr: [ BaseClass ] ) {
720
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
721
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
722
+ // CHECK-NEXT: switch_enum [[RESULT]]
723
+ if case is [ DerivedClass ] = arr { }
724
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
725
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
726
+ // CHECK-NEXT: switch_enum [[RESULT]]
727
+ guard case is [ DerivedClass ] = arr else { }
728
+ // CHECK: [[ARR_CAST_FN:%[0-9]+]] = function_ref @$ss21_arrayConditionalCastySayq_GSgSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Optional<Array<τ_0_1>>
729
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[ARR_CAST_FN]]<BaseClass, DerivedClass>
730
+ // CHECK-NEXT: switch_enum [[RESULT]]
731
+ while case is [ DerivedClass ] = arr { }
732
+ }
733
+ // CHECK: } // end sil function '$s10statements31test_isa_pattern_array_downcastyySayAA9BaseClassCGF'
734
+
735
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements36test_isa_pattern_dictionary_downcastyySDySSAA9BaseClassCGF : $@convention(thin) (@guaranteed Dictionary<String, BaseClass>) -> () {
736
+ func test_isa_pattern_dictionary_downcast( _ dict: Dictionary < String , BaseClass > ) {
737
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
738
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
739
+ // CHECK-NEXT: switch_enum [[RESULT]]
740
+ if case is [ String : DerivedClass ] = dict { }
741
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
742
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
743
+ // CHECK-NEXT: switch_enum [[RESULT]]
744
+ guard case is [ String : DerivedClass ] = dict else { }
745
+ // CHECK: [[DICT_CAST_FN:%[0-9]+]] = function_ref @$ss30_dictionaryDownCastConditionalySDyq0_q1_GSgSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Optional<Dictionary<τ_0_2, τ_0_3>>
746
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[DICT_CAST_FN]]<String, BaseClass, String, DerivedClass>
747
+ // CHECK-NEXT: switch_enum [[RESULT]]
748
+ while case is [ String : DerivedClass ] = dict { }
749
+ }
750
+ // CHECK: } // end sil function '$s10statements36test_isa_pattern_dictionary_downcastyySDySSAA9BaseClassCGF'
751
+
752
+ // CHECK-LABEL: sil hidden [ossa] @$s10statements29test_isa_pattern_set_downcastyyShyxGSHRzlF : $@convention(thin) <T where T : Hashable> (@guaranteed Set<T>) -> () {
753
+ func test_isa_pattern_set_downcast< T: Hashable > ( _ set: Set < T > ) {
754
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
755
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Int>
756
+ // CHECK-NEXT: switch_enum [[RESULT]]
757
+ if case is Set < Int > = set { }
758
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
759
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Int>
760
+ // CHECK-NEXT: switch_enum [[RESULT]]
761
+ guard case is Set < Int > = set else { }
762
+ // CHECK: [[SET_CAST_FN:%[0-9]+]] = function_ref @$ss23_setDownCastConditionalyShyq_GSgShyxGSHRzSHR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Optional<Set<τ_0_1>>
763
+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[SET_CAST_FN]]<T, Int>
764
+ // CHECK-NEXT: switch_enum [[RESULT]]
765
+ while case is Set < Int > = set { }
766
+ }
767
+ // CHECK: } // end sil function '$s10statements29test_isa_pattern_set_downcastyyShyxGSHRzlF'
768
+
660
769
// CHECK-LABEL: sil hidden [ossa] @$s10statements22let_else_tuple_bindingyS2i_SitSgF
661
770
func let_else_tuple_binding( _ a : ( Int , Int ) ? ) -> Int {
662
771
0 commit comments