Skip to content

Commit 4fa53c1

Browse files
authored
Merge pull request #22488 from Azoy/remove-lookupBoolType
[Sema] Remove lookupBoolType
2 parents b04ffed + e9f4217 commit 4fa53c1

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8013,6 +8013,12 @@ Expr *Solution::convertOptionalToBool(Expr *expr,
80138013
// Match the optional value against its `Some` case.
80148014
auto &ctx = tc.Context;
80158015
auto isSomeExpr = new (ctx) EnumIsCaseExpr(expr, ctx.getOptionalSomeDecl());
8016-
cs.setType(isSomeExpr, tc.lookupBoolType(cs.DC));
8016+
auto boolDecl = ctx.getBoolDecl();
8017+
8018+
if (!boolDecl) {
8019+
tc.diagnose(SourceLoc(), diag::broken_bool);
8020+
}
8021+
8022+
cs.setType(isSomeExpr, boolDecl ? boolDecl->getDeclaredType() : Type());
80178023
return isSomeExpr;
80188024
}

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,14 @@ namespace {
28002800
CS.getConstraintLocator(expr));
28012801

28022802
// The result is Bool.
2803-
return CS.getTypeChecker().lookupBoolType(CS.DC);
2803+
auto boolDecl = tc.Context.getBoolDecl();
2804+
2805+
if (!boolDecl) {
2806+
tc.diagnose(SourceLoc(), diag::broken_bool);
2807+
return Type();
2808+
}
2809+
2810+
return boolDecl->getDeclaredType();
28042811
}
28052812

28062813
Type visitDiscardAssignmentExpr(DiscardAssignmentExpr *expr) {

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,6 @@ ModuleDecl *TypeChecker::getStdlibModule(const DeclContext *dc) {
231231
return StdlibModule;
232232
}
233233

234-
Type TypeChecker::lookupBoolType(const DeclContext *dc) {
235-
if (!boolType) {
236-
boolType = ([&] {
237-
SmallVector<ValueDecl *, 2> results;
238-
getStdlibModule(dc)->lookupValue({}, Context.getIdentifier("Bool"),
239-
NLKind::QualifiedLookup, results);
240-
if (results.size() != 1) {
241-
diagnose(SourceLoc(), diag::broken_bool);
242-
return Type();
243-
}
244-
245-
auto tyDecl = dyn_cast<NominalTypeDecl>(results.front());
246-
if (!tyDecl) {
247-
diagnose(SourceLoc(), diag::broken_bool);
248-
return Type();
249-
}
250-
251-
return tyDecl->getDeclaredType();
252-
})();
253-
}
254-
return *boolType;
255-
}
256-
257234
/// Bind the given extension to the given nominal type.
258235
static void bindExtensionToNominal(ExtensionDecl *ext,
259236
NominalTypeDecl *nominal) {

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,6 @@ class TypeChecker final : public LazyResolver {
18481848
/// operator \c name appended to the expression.
18491849
Expr *findLHS(DeclContext *DC, Expr *E, Identifier name);
18501850

1851-
/// Look up the Bool type in the standard library.
1852-
Type lookupBoolType(const DeclContext *dc);
1853-
18541851
/// @}
18551852

18561853
/// \name Overload resolution

0 commit comments

Comments
 (0)