Skip to content

Commit 94dd355

Browse files
[CSDiag] Remove FailureDiagnosis:: visitObjectLiteralExpr from CSDiag
1 parent b53da32 commit 94dd355

File tree

2 files changed

+1
-70
lines changed

2 files changed

+1
-70
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
239239
bool visitTryExpr(TryExpr *E);
240240

241241
bool visitUnresolvedDotExpr(UnresolvedDotExpr *UDE);
242-
bool visitObjectLiteralExpr(ObjectLiteralExpr *E);
243242

244243
bool visitApplyExpr(ApplyExpr *AE);
245244
bool visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E);
@@ -1722,74 +1721,6 @@ visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E) {
17221721
return false;
17231722
}
17241723

1725-
/// When an object literal fails to typecheck because its protocol's
1726-
/// corresponding default type has not been set in the global namespace (e.g.
1727-
/// _ColorLiteralType), suggest that the user import the appropriate module for
1728-
/// the target.
1729-
bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
1730-
// Type check the argument first.
1731-
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), E);
1732-
if (!protocol)
1733-
return false;
1734-
auto constrName =
1735-
TypeChecker::getObjectLiteralConstructorName(CS.getASTContext(), E);
1736-
assert(constrName);
1737-
auto *constr = dyn_cast_or_null<ConstructorDecl>(
1738-
protocol->getSingleRequirement(constrName));
1739-
if (!constr)
1740-
return false;
1741-
auto paramType = TypeChecker::getObjectLiteralParameterType(E, constr);
1742-
if (!typeCheckChildIndependently(
1743-
E->getArg(), paramType, CTP_CallArgument))
1744-
return true;
1745-
1746-
// Conditions for showing this diagnostic:
1747-
// * The object literal protocol's default type is unimplemented
1748-
if (TypeChecker::getDefaultType(protocol, CS.DC))
1749-
return false;
1750-
// * The object literal has no contextual type
1751-
if (CS.getContextualType())
1752-
return false;
1753-
1754-
// Figure out what import to suggest.
1755-
auto &Ctx = CS.getASTContext();
1756-
const auto &target = Ctx.LangOpts.Target;
1757-
StringRef importModule;
1758-
StringRef importDefaultTypeName;
1759-
if (protocol == Ctx.getProtocol(KnownProtocolKind::ExpressibleByColorLiteral)) {
1760-
if (target.isMacOSX()) {
1761-
importModule = "AppKit";
1762-
importDefaultTypeName = "NSColor";
1763-
} else if (target.isiOS() || target.isTvOS()) {
1764-
importModule = "UIKit";
1765-
importDefaultTypeName = "UIColor";
1766-
}
1767-
} else if (protocol == Ctx.getProtocol(
1768-
KnownProtocolKind::ExpressibleByImageLiteral)) {
1769-
if (target.isMacOSX()) {
1770-
importModule = "AppKit";
1771-
importDefaultTypeName = "NSImage";
1772-
} else if (target.isiOS() || target.isTvOS()) {
1773-
importModule = "UIKit";
1774-
importDefaultTypeName = "UIImage";
1775-
}
1776-
} else if (protocol == Ctx.getProtocol(
1777-
KnownProtocolKind::ExpressibleByFileReferenceLiteral)) {
1778-
importModule = "Foundation";
1779-
importDefaultTypeName = "URL";
1780-
}
1781-
1782-
// Emit the diagnostic.
1783-
const auto plainName = E->getLiteralKindPlainName();
1784-
Ctx.Diags.diagnose(E->getLoc(), diag::object_literal_default_type_missing,
1785-
plainName);
1786-
if (!importModule.empty()) {
1787-
Ctx.Diags.diagnose(E->getLoc(), diag::object_literal_resolve_import,
1788-
importModule, importDefaultTypeName, plainName);
1789-
}
1790-
return true;
1791-
}
1792-
17931724
bool FailureDiagnosis::diagnoseMemberFailures(
17941725
Expr *E, Expr *baseExpr, ConstraintKind lookupKind, DeclNameRef memberName,
17951726
FunctionRefKind funcRefKind, ConstraintLocator *locator,

lib/Sema/ConstraintLocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
470470
auto branchElt = elt.castTo<LocatorPathElt::TernaryBranch>();
471471
out << (branchElt.forThen() ? "'then'" : "'else'")
472472
<< " branch of a ternary operator";
473-
break;
473+
break;
474474
}
475475
}
476476
out << ']';

0 commit comments

Comments
 (0)