Skip to content

Commit ee6c228

Browse files
committed
[Diagnostics] NFC: Move is{Array, Collection}Type helpers into FailureDiagnostic
1 parent 490548f commit ee6c228

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,12 +1261,11 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
12611261
ParameterTypeFlags())});
12621262

12631263
if (auto info = getFunctionArgApplyInfo(argLoc)) {
1264-
auto &cs = getConstraintSystem();
12651264
auto paramType = info->getParamType();
12661265
auto argType = getType(inoutExpr)->getWithoutSpecifierType();
12671266

12681267
PointerTypeKind ptr;
1269-
if (cs.isArrayType(argType) &&
1268+
if (isArrayType(argType) &&
12701269
paramType->getAnyPointerElementType(ptr) &&
12711270
(ptr == PTK_UnsafePointer || ptr == PTK_UnsafeRawPointer)) {
12721271
emitDiagnosticAt(inoutExpr->getLoc(),
@@ -3403,27 +3402,25 @@ bool MissingMemberFailure::diagnoseForDynamicCallable() const {
34033402
}
34043403

34053404
bool MissingMemberFailure::diagnoseInLiteralCollectionContext() const {
3406-
auto &cs = getConstraintSystem();
34073405
auto *expr = castToExpr(getAnchor());
3408-
auto *parentExpr = cs.getParentExpr(expr);
3406+
auto *parentExpr = findParentExpr(expr);
34093407
auto &solution = getSolution();
34103408

34113409
if (!(parentExpr && isa<UnresolvedMemberExpr>(expr)))
34123410
return false;
34133411

34143412
auto parentType = getType(parentExpr);
34153413

3416-
if (!cs.isCollectionType(parentType) && !parentType->is<TupleType>())
3414+
if (!isCollectionType(parentType) && !parentType->is<TupleType>())
34173415
return false;
34183416

34193417
if (isa<TupleExpr>(parentExpr)) {
3420-
parentExpr = cs.getParentExpr(parentExpr);
3418+
parentExpr = findParentExpr(parentExpr);
34213419
if (!parentExpr)
34223420
return false;
34233421
}
34243422

3425-
if (auto *defaultableVar =
3426-
cs.getType(parentExpr)->getAs<TypeVariableType>()) {
3423+
if (auto *defaultableVar = getType(parentExpr)->getAs<TypeVariableType>()) {
34273424
if (solution.DefaultedConstraints.count(
34283425
defaultableVar->getImpl().getLocator()) != 0) {
34293426
emitDiagnostic(diag::unresolved_member_no_inference, getName());

lib/Sema/CSDiagnostics.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ class FailureDiagnostic {
202202
Type type,
203203
llvm::function_ref<void(GenericTypeParamType *, Type)> substitution =
204204
[](GenericTypeParamType *, Type) {});
205+
206+
bool isCollectionType(Type type) const {
207+
auto &cs = getConstraintSystem();
208+
return bool(cs.isCollectionType(type));
209+
}
210+
211+
bool isArrayType(Type type) const {
212+
auto &cs = getConstraintSystem();
213+
return bool(cs.isArrayType(type));
214+
}
205215
};
206216

207217
/// Base class for all of the diagnostics related to generic requirement

0 commit comments

Comments
 (0)