@@ -3659,27 +3659,37 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
3659
3659
}
3660
3660
case PatternKind::Named: {
3661
3661
auto named = cast<NamedPattern>(pattern);
3662
+ auto ty = getPatternType ();
3663
+ if (S.skipTypeIfInvalid (ty, named->getLoc ()))
3664
+ break ;
3662
3665
3663
3666
unsigned abbrCode = S.DeclTypeAbbrCodes [NamedPatternLayout::Code];
3664
3667
NamedPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3665
3668
S.addDeclRef (named->getDecl ()),
3666
- S.addTypeRef (getPatternType () ));
3669
+ S.addTypeRef (ty ));
3667
3670
break ;
3668
3671
}
3669
3672
case PatternKind::Any: {
3673
+ auto ty = getPatternType ();
3674
+ if (S.skipTypeIfInvalid (ty, pattern->getLoc ()))
3675
+ break ;
3676
+
3670
3677
unsigned abbrCode = S.DeclTypeAbbrCodes [AnyPatternLayout::Code];
3671
3678
auto anyPattern = cast<AnyPattern>(pattern);
3672
3679
AnyPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3673
- S.addTypeRef (getPatternType () ),
3680
+ S.addTypeRef (ty ),
3674
3681
anyPattern->isAsyncLet ());
3675
3682
break ;
3676
3683
}
3677
3684
case PatternKind::Typed: {
3678
3685
auto typed = cast<TypedPattern>(pattern);
3686
+ auto ty = getPatternType ();
3687
+ if (S.skipTypeIfInvalid (ty, typed->getTypeRepr ()))
3688
+ break ;
3679
3689
3680
3690
unsigned abbrCode = S.DeclTypeAbbrCodes [TypedPatternLayout::Code];
3681
3691
TypedPatternLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3682
- S.addTypeRef (getPatternType () ));
3692
+ S.addTypeRef (ty ));
3683
3693
writePattern (typed->getSubPattern ());
3684
3694
break ;
3685
3695
}
@@ -6813,7 +6823,7 @@ bool Serializer::skipDeclIfInvalid(const Decl *decl) {
6813
6823
}
6814
6824
6815
6825
bool Serializer::skipTypeIfInvalid (Type ty, TypeRepr *tyRepr) {
6816
- if (ty || allowCompilerErrors ())
6826
+ if ((ty && !ty-> hasError ()) || allowCompilerErrors ())
6817
6827
return false ;
6818
6828
6819
6829
if (Options.EnableSerializationRemarks ) {
@@ -6825,6 +6835,19 @@ bool Serializer::skipTypeIfInvalid(Type ty, TypeRepr *tyRepr) {
6825
6835
return true ;
6826
6836
}
6827
6837
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
+
6828
6851
void serialization::writeToStream (
6829
6852
raw_ostream &os, ModuleOrSourceFile DC, const SILModule *M,
6830
6853
const SerializationOptions &options,
0 commit comments