@@ -542,6 +542,95 @@ final class PredicateCodableTests: XCTestCase {
542542 XCTAssertThrowsError ( try _encodeDecode ( predicate, for: EmptyConfig . self) )
543543 XCTAssertThrowsError ( try _encodeDecode ( predicate) )
544544 }
545+
546+ func testCapturedVariadicTypes( ) throws {
547+ #if !canImport(ReflectionInternal, _version: "18")
548+ throw XCTSkip ( " Insufficient ReflectionInternal version for this test " )
549+ #else
550+ struct A < each T > : Equatable , Codable {
551+ init ( _: repeat ( each T ) . Type) { }
552+
553+ func encode( to encoder: Encoder ) throws {
554+ var container = encoder. singleValueContainer ( )
555+ try container. encodeNil ( )
556+ }
557+
558+ init ( from decoder: Decoder ) throws {
559+ var container = try decoder. singleValueContainer ( )
560+ guard container. decodeNil ( ) else {
561+ throw DecodingError . dataCorrupted ( . init( codingPath: container. codingPath, debugDescription: " Did not find encoded nil " ) )
562+ }
563+ }
564+ }
565+
566+ let a = A ( String . self, Int . self)
567+
568+ let predicate = Predicate< Int> { _ in
569+ // a == a
570+ PredicateExpressions . build_Equal (
571+ lhs: PredicateExpressions . build_Arg ( a) ,
572+ rhs: PredicateExpressions . build_Arg ( a)
573+ )
574+ }
575+
576+ let encoder = JSONEncoder ( )
577+ var config = PredicateCodableConfiguration . standardConfiguration
578+ config. allowPartialType ( A< > . self, identifier: " PredicateCodableTests.A " )
579+ XCTAssertThrowsError ( try encoder. encode ( predicate, configuration: config) ) {
580+ XCTAssertTrue ( String ( describing: $0) . contains ( " type is not allowed because it contains type pack parameters " ) )
581+ }
582+
583+ let json = """
584+ [
585+ {
586+ " expression " : [
587+ null,
588+ null
589+ ],
590+ " structure " : {
591+ " identifier " : " PredicateExpressions.Equal " ,
592+ " args " : [
593+ {
594+ " identifier " : " PredicateExpressions.Value " ,
595+ " args " : [
596+ {
597+ " identifier " : " PredicateCodableTests.A " ,
598+ " args " : [
599+ " Swift.String " ,
600+ " Swift.Int "
601+ ]
602+ }
603+ ]
604+ },
605+ {
606+ " args " : [
607+ {
608+ " identifier " : " PredicateCodableTests.A " ,
609+ " args " : [
610+ " Swift.String " ,
611+ " Swift.Int "
612+ ]
613+ }
614+ ],
615+ " identifier " : " PredicateExpressions.Value "
616+ }
617+ ]
618+ },
619+ " variable " : [
620+ {
621+ " key " : 0
622+ }
623+ ]
624+ }
625+ ]
626+ """
627+
628+ let decoder = JSONDecoder ( )
629+ XCTAssertThrowsError ( try decoder. decode ( Predicate< Int> . self , from: json. data ( using: . utf8) !, configuration: config) ) {
630+ XCTAssertTrue ( String ( describing: $0) . contains ( " type is not allowed because it contains type pack parameters " ) )
631+ }
632+ #endif
633+ }
545634}
546635
547636#endif // FOUNDATION_FRAMEWORK
0 commit comments