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