Skip to content

Commit 17f7598

Browse files
committed
[Diagnostics] NFC: Remove obsolete diagnoseContextualConversionError
1 parent 2875aa8 commit 17f7598

File tree

3 files changed

+8
-62
lines changed

3 files changed

+8
-62
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
195195
/// Emit an ambiguity diagnostic about the specified expression.
196196
void diagnoseAmbiguity(Expr *E);
197197

198-
/// Attempt to produce a diagnostic for a mismatch between an expression's
199-
/// type and its assumed contextual type.
200-
bool diagnoseContextualConversionError(Expr *expr, Type contextualType,
201-
ContextualTypePurpose CTP,
202-
Type suggestedType = Type());
203-
204198
private:
205199
/// Validate potential contextual type for type-checking one of the
206200
/// sub-expressions, usually correct/valid types are the ones which
@@ -500,51 +494,6 @@ DeclContext *FailureDiagnosis::findDeclContext(Expr *subExpr) const {
500494
return finder.DC;
501495
}
502496

503-
bool FailureDiagnosis::diagnoseContextualConversionError(
504-
Expr *expr, Type contextualType, ContextualTypePurpose CTP,
505-
Type suggestedType) {
506-
// If the constraint system has a contextual type, then we can test to see if
507-
// this is the problem that prevents us from solving the system.
508-
if (!contextualType)
509-
return false;
510-
511-
// Try re-type-checking the expression without the contextual type to see if
512-
// it can work without it. If so, the contextual type is the problem. We
513-
// force a recheck, because "expr" is likely in our table with the extra
514-
// contextual constraint that we know we are relaxing.
515-
TCCOptions options = TCC_ForceRecheck;
516-
if (contextualType->is<InOutType>())
517-
options |= TCC_AllowLValue;
518-
519-
auto *recheckedExpr = typeCheckChildIndependently(expr, options);
520-
auto exprType = recheckedExpr ? CS.getType(recheckedExpr) : Type();
521-
522-
// If there is a suggested type and re-typecheck failed, let's use it.
523-
if (!exprType)
524-
exprType = suggestedType;
525-
526-
// If it failed and diagnosed something, then we're done.
527-
if (!exprType)
528-
return CS.getASTContext().Diags.hadAnyError();
529-
530-
// If we don't have a type for the expression, then we cannot use it in
531-
// conversion constraint diagnostic generation. If the types match, then it
532-
// must not be the contextual type that is the problem.
533-
if (isUnresolvedOrTypeVarType(exprType) || exprType->isEqual(contextualType))
534-
return false;
535-
536-
// Don't attempt fixits if we have an unsolved type variable, since
537-
// the recovery path's recursion into the type checker via typeCheckCast()
538-
// will confuse matters.
539-
if (exprType->hasTypeVariable())
540-
return false;
541-
542-
ContextualFailure failure(
543-
CS, CTP, exprType, contextualType,
544-
CS.getConstraintLocator(expr, LocatorPathElt::ContextualType()));
545-
return failure.diagnoseAsError();
546-
}
547-
548497
//===----------------------------------------------------------------------===//
549498
// Diagnose assigning variable to itself.
550499
//===----------------------------------------------------------------------===//
@@ -1256,13 +1205,6 @@ void ConstraintSystem::diagnoseFailureFor(SolutionApplicationTarget target) {
12561205
if (diagnosis.diagnoseExprFailure())
12571206
return;
12581207

1259-
// If this is a contextual conversion problem, dig out some information.
1260-
if (diagnosis.diagnoseContextualConversionError(
1261-
expr,
1262-
getContextualType(expr),
1263-
getContextualTypePurpose(expr)))
1264-
return;
1265-
12661208
// If no one could find a problem with this expression or constraint system,
12671209
// then it must be well-formed... but is ambiguous. Handle this by diagnostic
12681210
// various cases that come up.

test/Constraints/closures.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,13 @@ extension Collection {
456456
}
457457
}
458458
func fn_r28909024(n: Int) {
459-
return (0..<10).r28909024 { // expected-error {{unexpected non-void return value in void function}}
459+
// FIXME(diagnostics): Unfortunately there is no easy way to fix this diagnostic issue at the moment
460+
// because the problem is related to ordering of the bindings - we'd attempt to bind result of the expression
461+
// to contextual type of `Void` which prevents solver from discovering correct types for range - 0..<10
462+
// (since both arguments are literal they are ranked lower than contextual type).
463+
//
464+
// Good diagnostic for this is - `unexpected non-void return value in void function`
465+
return (0..<10).r28909024 { // expected-error {{expression type 'Range<Int>.Index' (aka 'Int') is ambiguous without more context}}
460466
_ in true
461467
}
462468
}

test/Parse/matching_patterns.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,4 @@ case (_?)?: break // expected-warning {{case is already handled by previous patt
332332
let (responseObject: Int?) = op1
333333
// expected-error @-1 {{expected ',' separator}} {{25-25=,}}
334334
// expected-error @-2 {{expected pattern}}
335-
// expected-error @-3 {{cannot convert value of type 'Int?' to specified type '(responseObject: _)'}}
336-
337-
335+
// expected-error @-3 {{expression type 'Int?' is ambiguous without more context}}

0 commit comments

Comments
 (0)