@@ -3659,27 +3659,37 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
36593659 }
36603660 case PatternKind::Named: {
36613661 auto named = cast<NamedPattern>(pattern);
3662+ auto ty = getPatternType ();
3663+ if (S.skipTypeIfInvalid (ty, named->getLoc ()))
3664+ break ;
36623665
36633666 unsigned abbrCode = S.DeclTypeAbbrCodes [NamedPatternLayout::Code];
36643667 NamedPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
36653668 S.addDeclRef (named->getDecl ()),
3666- S.addTypeRef (getPatternType () ));
3669+ S.addTypeRef (ty ));
36673670 break ;
36683671 }
36693672 case PatternKind::Any: {
3673+ auto ty = getPatternType ();
3674+ if (S.skipTypeIfInvalid (ty, pattern->getLoc ()))
3675+ break ;
3676+
36703677 unsigned abbrCode = S.DeclTypeAbbrCodes [AnyPatternLayout::Code];
36713678 auto anyPattern = cast<AnyPattern>(pattern);
36723679 AnyPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3673- S.addTypeRef (getPatternType () ),
3680+ S.addTypeRef (ty ),
36743681 anyPattern->isAsyncLet ());
36753682 break ;
36763683 }
36773684 case PatternKind::Typed: {
36783685 auto typed = cast<TypedPattern>(pattern);
3686+ auto ty = getPatternType ();
3687+ if (S.skipTypeIfInvalid (ty, typed->getTypeRepr ()))
3688+ break ;
36793689
36803690 unsigned abbrCode = S.DeclTypeAbbrCodes [TypedPatternLayout::Code];
36813691 TypedPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3682- S.addTypeRef (getPatternType () ));
3692+ S.addTypeRef (ty ));
36833693 writePattern (typed->getSubPattern ());
36843694 break ;
36853695 }
@@ -6813,7 +6823,7 @@ bool Serializer::skipDeclIfInvalid(const Decl *decl) {
68136823}
68146824
68156825bool Serializer::skipTypeIfInvalid (Type ty, TypeRepr *tyRepr) {
6816- if (ty || allowCompilerErrors ())
6826+ if ((ty && !ty-> hasError ()) || allowCompilerErrors ())
68176827 return false ;
68186828
68196829 if (Options.EnableSerializationRemarks ) {
@@ -6825,6 +6835,19 @@ bool Serializer::skipTypeIfInvalid(Type ty, TypeRepr *tyRepr) {
68256835 return true ;
68266836}
68276837
6838+ bool Serializer::skipTypeIfInvalid (Type ty, SourceLoc loc) {
6839+ if ((ty && !ty->hasError ()) || allowCompilerErrors ())
6840+ return false ;
6841+
6842+ if (Options.EnableSerializationRemarks ) {
6843+ getASTContext ().Diags .diagnose (
6844+ loc, diag::serialization_skipped_invalid_type_unknown_name);
6845+ }
6846+
6847+ hadError = true ;
6848+ return true ;
6849+ }
6850+
68286851void serialization::writeToStream (
68296852 raw_ostream &os, ModuleOrSourceFile DC, const SILModule *M,
68306853 const SerializationOptions &options,
0 commit comments