Skip to content

Commit 2910d54

Browse files
committed
Fix <rdar://problem/24267414> QoI: error: cannot convert value of type 'Int' to specified type 'Int'
When a contextual conversion has a matching type, don't diagnose it as a conversion error, the problem is due to something else (in this case, an unresolved archetype somewhere else in the expression). Before: t.swift:6:17: error: cannot convert value of type 'Int' to specified type 'Int' After: t.swift:6:17: error: generic parameter 'T' could not be inferred This should still be a bit better to provide information about where the T archetype came from, but at least now it isn't completely wrong diagnostic.
1 parent 8da10e3 commit 2910d54

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,8 @@ bool FailureDiagnosis::diagnoseContextualConversionError() {
28942894
return true;
28952895
}
28962896

2897-
if (isUnresolvedOrTypeVarType(exprType))
2897+
if (isUnresolvedOrTypeVarType(exprType) ||
2898+
exprType->isEqual(contextualType))
28982899
return false;
28992900

29002901
// The conversion destination of throw is always ErrorType (at the moment)
@@ -2960,9 +2961,10 @@ bool FailureDiagnosis::diagnoseContextualConversionError() {
29602961
}
29612962

29622963
// If we don't have a type for the expression, then we cannot use it in
2963-
// conversion constraint diagnostic generation.
2964-
if (isUnresolvedOrTypeVarType(exprType)) {
2965-
// We can't do anything smart.
2964+
// conversion constraint diagnostic generation. If the types match, then it
2965+
// must not be the contextual type that is the problem.
2966+
if (isUnresolvedOrTypeVarType(exprType) ||
2967+
exprType->isEqual(contextualType)) {
29662968
return false;
29672969
}
29682970

test/Constraints/generics.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,9 @@ func r22509125<T>(a : T?) { // expected-note {{in call to function 'r22509125'}}
184184
}
185185

186186

187+
// <rdar://problem/24267414> QoI: error: cannot convert value of type 'Int' to specified type 'Int'
188+
struct R24267414<T> {
189+
static func foo() -> Int {}
190+
}
191+
var _ : Int = R24267414.foo() // expected-error {{generic parameter 'T' could not be inferred}}
192+

0 commit comments

Comments
 (0)