Skip to content

Commit a21c748

Browse files
committed
Sema: Fix crash on Linux if ObjCBool type is not present
1 parent 0004bc4 commit a21c748

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,9 +2166,6 @@ ERROR(builtin_string_literal_broken_proto,none,
21662166
ERROR(string_literal_broken_proto,none,
21672167
"protocol 'ExpressibleByStringLiteral' is broken", ())
21682168

2169-
ERROR(bool_type_broken,none,
2170-
"could not find a Bool type defined for 'is'", ())
2171-
21722169
// Array literals
21732170
ERROR(array_protocol_broken,none,
21742171
"ExpressibleByArrayLiteral protocol definition is broken", ())

lib/Sema/TypeCheckType.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,8 +3025,19 @@ bool TypeChecker::isRepresentableInObjC(
30253025
// Functions that return nothing (void) can be throwing; they indicate
30263026
// failure with a 'false' result.
30273027
kind = ForeignErrorConvention::ZeroResult;
3028-
errorResultType = Context.getObjCBoolDecl()
3029-
->getDeclaredInterfaceType()->getCanonicalType();
3028+
NominalTypeDecl *boolDecl = Context.getObjCBoolDecl();
3029+
// On Linux, we might still run @objc tests even though there's
3030+
// no ObjectiveC Foundation, so use Swift.Bool instead of crapping
3031+
// out.
3032+
if (boolDecl == nullptr)
3033+
boolDecl = Context.getBoolDecl();
3034+
3035+
if (boolDecl == nullptr) {
3036+
diagnose(AFD->getLoc(), diag::broken_bool);
3037+
return false;
3038+
}
3039+
3040+
errorResultType = boolDecl->getDeclaredType()->getCanonicalType();
30303041
} else if (!resultType->getAnyOptionalObjectType() &&
30313042
isBridgedToObjectiveCClass(dc, resultType)) {
30323043
// Functions that return a (non-optional) type bridged to Objective-C

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ Type TypeChecker::lookupBoolType(const DeclContext *dc) {
243243
getStdlibModule(dc)->lookupValue({}, Context.getIdentifier("Bool"),
244244
NLKind::QualifiedLookup, results);
245245
if (results.size() != 1) {
246-
diagnose(SourceLoc(), diag::bool_type_broken);
246+
diagnose(SourceLoc(), diag::broken_bool);
247247
return Type();
248248
}
249249

250250
auto tyDecl = dyn_cast<TypeDecl>(results.front());
251251
if (!tyDecl) {
252-
diagnose(SourceLoc(), diag::bool_type_broken);
252+
diagnose(SourceLoc(), diag::broken_bool);
253253
return Type();
254254
}
255255

0 commit comments

Comments
 (0)