Skip to content

Commit 59a2545

Browse files
committed
[Serialization] Drop functions whose types can't be imported.
This doesn't handle generic functions with problems in their requirements, but it's a step.
1 parent 3ee8e84 commit 59a2545

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,10 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
27562756
return llvm::make_error<OverrideError>(name);
27572757
}
27582758

2759+
auto canonicalType = getTypeChecked(canonicalTypeID);
2760+
if (!canonicalType)
2761+
return llvm::make_error<TypeError>(name, takeErrorInfo(canonicalType.takeError()));
2762+
27592763
auto DC = getDeclContext(contextID);
27602764
if (declOrOffset.isComplete())
27612765
return declOrOffset;
@@ -4021,9 +4025,15 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
40214025
auto info = GenericFunctionType::ExtInfo(*rep, throws);
40224026

40234027
auto sig = GenericSignature::get(genericParams, requirements);
4024-
typeOrOffset = GenericFunctionType::get(sig,
4025-
getType(inputID),
4026-
getType(resultID),
4028+
4029+
auto inputTy = getTypeChecked(inputID);
4030+
if (!inputTy)
4031+
return inputTy.takeError();
4032+
auto resultTy = getTypeChecked(resultID);
4033+
if (!resultTy)
4034+
return resultTy.takeError();
4035+
4036+
typeOrOffset = GenericFunctionType::get(sig, inputTy.get(), resultTy.get(),
40274037
info);
40284038
break;
40294039
}

test/Serialization/Recovery/typedefs.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ let _: Int32? = useAssoc(AnotherType.self)
3636
let _ = wrapped // expected-error {{use of unresolved identifier 'wrapped'}}
3737
let _ = unwrapped // okay
3838

39+
_ = usesWrapped(nil) // expected-error {{use of unresolved identifier 'usesWrapped'}}
40+
_ = usesUnwrapped(nil) // expected-error {{nil is not compatible with expected argument type 'Int32'}}
41+
3942
#endif // VERIFY
4043

4144
#else // TEST
@@ -124,4 +127,19 @@ public var normalFirst: Int?, wrappedSecond: WrappedInt?
124127
// CHECK-RECOVERY-NEGATIVE-NOT: var wrappedFourth:
125128
public var wrappedThird, wrappedFourth: WrappedInt?
126129

130+
// CHECK-DAG: func usesWrapped(_ wrapped: WrappedInt)
131+
// CHECK-RECOVERY-NEGATIVE-NOT: func usesWrapped(
132+
public func usesWrapped(_ wrapped: WrappedInt) {}
133+
// CHECK-DAG: func usesUnwrapped(_ unwrapped: UnwrappedInt)
134+
// CHECK-RECOVERY-DAG: func usesUnwrapped(_ unwrapped: Int32)
135+
public func usesUnwrapped(_ unwrapped: UnwrappedInt) {}
136+
137+
// CHECK-DAG: func returnsWrapped() -> WrappedInt
138+
// CHECK-RECOVERY-NEGATIVE-NOT: func returnsWrapped(
139+
public func returnsWrapped() -> WrappedInt { fatalError() }
140+
141+
// CHECK-DAG: func returnsWrappedGeneric<T>(_: T.Type) -> WrappedInt
142+
// CHECK-RECOVERY-NEGATIVE-NOT: func returnsWrappedGeneric
143+
public func returnsWrappedGeneric<T>(_: T.Type) -> WrappedInt { fatalError() }
144+
127145
#endif // TEST

0 commit comments

Comments
 (0)