mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Serialization: Skip patterns with invalid types.
Prevents a crash during module emission with `-enable-lazy-typechecking` when the type of a `Pattern` cannot be resolved.
This commit is contained in:
@@ -3659,27 +3659,37 @@ private:
|
||||
}
|
||||
case PatternKind::Named: {
|
||||
auto named = cast<NamedPattern>(pattern);
|
||||
auto ty = getPatternType();
|
||||
if (S.skipTypeIfInvalid(ty, named->getLoc()))
|
||||
break;
|
||||
|
||||
unsigned abbrCode = S.DeclTypeAbbrCodes[NamedPatternLayout::Code];
|
||||
NamedPatternLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
S.addDeclRef(named->getDecl()),
|
||||
S.addTypeRef(getPatternType()));
|
||||
S.addTypeRef(ty));
|
||||
break;
|
||||
}
|
||||
case PatternKind::Any: {
|
||||
auto ty = getPatternType();
|
||||
if (S.skipTypeIfInvalid(ty, pattern->getLoc()))
|
||||
break;
|
||||
|
||||
unsigned abbrCode = S.DeclTypeAbbrCodes[AnyPatternLayout::Code];
|
||||
auto anyPattern = cast<AnyPattern>(pattern);
|
||||
AnyPatternLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
S.addTypeRef(getPatternType()),
|
||||
S.addTypeRef(ty),
|
||||
anyPattern->isAsyncLet());
|
||||
break;
|
||||
}
|
||||
case PatternKind::Typed: {
|
||||
auto typed = cast<TypedPattern>(pattern);
|
||||
auto ty = getPatternType();
|
||||
if (S.skipTypeIfInvalid(ty, typed->getTypeRepr()))
|
||||
break;
|
||||
|
||||
unsigned abbrCode = S.DeclTypeAbbrCodes[TypedPatternLayout::Code];
|
||||
TypedPatternLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
S.addTypeRef(getPatternType()));
|
||||
S.addTypeRef(ty));
|
||||
writePattern(typed->getSubPattern());
|
||||
break;
|
||||
}
|
||||
@@ -6813,7 +6823,7 @@ bool Serializer::skipDeclIfInvalid(const Decl *decl) {
|
||||
}
|
||||
|
||||
bool Serializer::skipTypeIfInvalid(Type ty, TypeRepr *tyRepr) {
|
||||
if (ty || allowCompilerErrors())
|
||||
if ((ty && !ty->hasError()) || allowCompilerErrors())
|
||||
return false;
|
||||
|
||||
if (Options.EnableSerializationRemarks) {
|
||||
@@ -6825,6 +6835,19 @@ bool Serializer::skipTypeIfInvalid(Type ty, TypeRepr *tyRepr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Serializer::skipTypeIfInvalid(Type ty, SourceLoc loc) {
|
||||
if ((ty && !ty->hasError()) || allowCompilerErrors())
|
||||
return false;
|
||||
|
||||
if (Options.EnableSerializationRemarks) {
|
||||
getASTContext().Diags.diagnose(
|
||||
loc, diag::serialization_skipped_invalid_type_unknown_name);
|
||||
}
|
||||
|
||||
hadError = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void serialization::writeToStream(
|
||||
raw_ostream &os, ModuleOrSourceFile DC, const SILModule *M,
|
||||
const SerializationOptions &options,
|
||||
|
||||
Reference in New Issue
Block a user