Skip to content

Commit 0c33206

Browse files
[Type] Fail early on Type::getForeignRepresentable if type has error
1 parent 384c373 commit 0c33206

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/AST/Type.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,16 @@ getObjCObjectRepresentable(Type type, const DeclContext *dc) {
22082208
static std::pair<ForeignRepresentableKind, ProtocolConformance *>
22092209
getForeignRepresentable(Type type, ForeignLanguage language,
22102210
const DeclContext *dc) {
2211+
// Local function that simply produces a failing result.
2212+
auto failure = []() -> std::pair<ForeignRepresentableKind,
2213+
ProtocolConformance *> {
2214+
return { ForeignRepresentableKind::None, nullptr };
2215+
};
2216+
2217+
// If type has an error let's fail early.
2218+
if (type->hasError())
2219+
return failure();
2220+
22112221
// Look through one level of optional type, but remember that we did.
22122222
bool wasOptional = false;
22132223
if (auto valueType = type->getOptionalObjectType()) {
@@ -2222,12 +2232,6 @@ getForeignRepresentable(Type type, ForeignLanguage language,
22222232
return { representable, nullptr };
22232233
}
22242234

2225-
// Local function that simply produces a failing result.
2226-
auto failure = []() -> std::pair<ForeignRepresentableKind,
2227-
ProtocolConformance *> {
2228-
return { ForeignRepresentableKind::None, nullptr };
2229-
};
2230-
22312235
// Function types.
22322236
if (auto functionType = type->getAs<FunctionType>()) {
22332237
// Cannot handle throwing functions.

0 commit comments

Comments
 (0)