Skip to content

Commit f2942eb

Browse files
committed
[Diagnostics] Port diagnostics related to array literal use
1 parent a584202 commit f2942eb

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 55 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 visitArrayExpr(ArrayExpr *E);
243242
bool visitDictionaryExpr(DictionaryExpr *E);
244243
bool visitObjectLiteralExpr(ObjectLiteralExpr *E);
245244

@@ -1724,60 +1723,6 @@ visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E) {
17241723
return false;
17251724
}
17261725

1727-
bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
1728-
// If we had a contextual type, then it either conforms to
1729-
// ExpressibleByArrayLiteral or it is an invalid contextual type.
1730-
auto contextualType = CS.getContextualType();
1731-
if (!contextualType) {
1732-
return false;
1733-
}
1734-
1735-
// If our contextual type is an optional, look through them, because we're
1736-
// surely initializing whatever is inside.
1737-
contextualType = contextualType->lookThroughAllOptionalTypes();
1738-
1739-
// Validate that the contextual type conforms to ExpressibleByArrayLiteral and
1740-
// figure out what the contextual element type is in place.
1741-
auto ALC =
1742-
TypeChecker::getProtocol(CS.getASTContext(), E->getLoc(),
1743-
KnownProtocolKind::ExpressibleByArrayLiteral);
1744-
if (!ALC)
1745-
return visitExpr(E);
1746-
1747-
// Check to see if the contextual type conforms.
1748-
auto Conformance = TypeChecker::conformsToProtocol(
1749-
contextualType, ALC, CS.DC, ConformanceCheckFlags::InExpression);
1750-
if (Conformance) {
1751-
Type contextualElementType =
1752-
Conformance
1753-
.getTypeWitnessByName(contextualType,
1754-
CS.getASTContext().Id_ArrayLiteralElement)
1755-
->getDesugaredType();
1756-
1757-
// Type check each of the subexpressions in place, passing down the contextual
1758-
// type information if we have it.
1759-
for (auto elt : E->getElements()) {
1760-
if (typeCheckChildIndependently(elt, contextualElementType,
1761-
CTP_ArrayElement) == nullptr) {
1762-
return true;
1763-
}
1764-
}
1765-
1766-
return false;
1767-
}
1768-
1769-
ContextualFailure failure(CS, CS.getType(E), contextualType,
1770-
CS.getConstraintLocator(E));
1771-
if (failure.diagnoseConversionToDictionary())
1772-
return true;
1773-
1774-
// If that didn't turn up an issue, then we don't know what to do.
1775-
// TODO: When a contextual type is missing, we could try to diagnose cases
1776-
// where the element types mismatch... but theoretically they should type
1777-
// unify to Any, so that could never happen?
1778-
return false;
1779-
}
1780-
17811726
bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
17821727
Type contextualKeyType, contextualValueType;
17831728
auto keyTypePurpose = CTP_Unused, valueTypePurpose = CTP_Unused;

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
670670
break;
671671
}
672672

673+
case ConstraintLocator::TupleElement: {
674+
if (auto *array = dyn_cast<ArrayExpr>(getRawAnchor()))
675+
diagnostic = getDiagnosticFor(CTP_ArrayElement);
676+
break;
677+
}
678+
673679
default:
674680
return false;
675681
}

0 commit comments

Comments
 (0)