Skip to content

Commit ac1046f

Browse files
committed
---
yaml --- r: 349444 b: refs/heads/master-next c: ae932e8 h: refs/heads/master
1 parent 3434e1a commit ac1046f

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 29b9aec1ad13365727a66e7e05a0866f310a02ba
3+
refs/heads/master-next: ae932e864c6f629ba1f29b42eb650d1549a7cde2
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/Sema/CSSimplify.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,20 @@ static bool isSingleTupleParam(ASTContext &ctx,
12471247
return (paramType->is<TupleType>() || paramType->isTypeVariableOrMember());
12481248
}
12491249

1250+
static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
1251+
Type type2, Expr *anchor,
1252+
ArrayRef<LocatorPathElt> path);
1253+
1254+
static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
1255+
Type type2,
1256+
ConstraintLocatorBuilder locator) {
1257+
SmallVector<LocatorPathElt, 4> path;
1258+
if (auto *anchor = locator.getLocatorParts(path)) {
1259+
return fixRequirementFailure(cs, type1, type2, anchor, path);
1260+
}
1261+
return nullptr;
1262+
}
1263+
12501264
/// Attempt to fix missing arguments by introducing type variables
12511265
/// and inferring their types from parameters.
12521266
static bool fixMissingArguments(ConstraintSystem &cs, Expr *anchor,
@@ -1748,20 +1762,12 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
17481762
// Match up the generic arguments, exactly.
17491763

17501764
if (shouldAttemptFixes()) {
1751-
bool forRequirement = false;
1752-
if (auto last = locator.last()) {
1753-
forRequirement = last->is<LocatorPathElt::AnyRequirement>();
1754-
}
1755-
1756-
// Optionals and arrays have a lot of special diagnostics and only one
1765+
// Optionals have a lot of special diagnostics and only one
17571766
// generic argument so if we' re dealing with one, don't produce generic
17581767
// arguments mismatch fixes.
1759-
// TODO(diagnostics): Move Optional and Array diagnostics over to the
1768+
// TODO(diagnostics): Move Optional diagnostics over to the
17601769
// new framework.
1761-
bool isOptional = bound1->getDecl()->isOptionalDecl();
1762-
bool isArray = isArrayType(bound1).hasValue();
1763-
1764-
if (forRequirement || isOptional || isArray)
1770+
if (bound1->getDecl()->isOptionalDecl())
17651771
return matchDeepTypeArguments(*this, subflags, args1, args2, locator);
17661772

17671773
SmallVector<unsigned, 4> mismatches;
@@ -1772,6 +1778,18 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
17721778
if (mismatches.empty())
17731779
return result;
17741780

1781+
if (auto last = locator.last()) {
1782+
if (last->is<LocatorPathElt::AnyRequirement>()) {
1783+
if (auto *fix = fixRequirementFailure(*this, type1, type2, locator)) {
1784+
if (recordFix(fix))
1785+
return getTypeMatchFailure(locator);
1786+
1787+
increaseScore(SK_Fix, mismatches.size());
1788+
return getTypeMatchSuccess();
1789+
}
1790+
}
1791+
}
1792+
17751793
auto *fix = GenericArgumentsMismatch::create(
17761794
*this, type1, type2, mismatches, getConstraintLocator(locator));
17771795

@@ -2503,8 +2521,16 @@ bool ConstraintSystem::repairFailures(
25032521
if (lhs->hasDependentMember() || rhs->hasDependentMember())
25042522
break;
25052523

2524+
// If requirement is something like `T == [Int]` let's let
2525+
// type matcher a chance to match generic parameters before
2526+
// recording a fix, because then we'll know exactly how many
2527+
// generic parameters did not match.
2528+
if (hasConversionOrRestriction(ConversionRestrictionKind::DeepEquality))
2529+
break;
2530+
25062531
auto reqElt = elt.castTo<LocatorPathElt::AnyRequirement>();
25072532
auto reqKind = reqElt.getRequirementKind();
2533+
25082534
if (hasFixedRequirement(lhs, reqKind, rhs))
25092535
return true;
25102536

branches/master-next/test/Sema/diag_type_conversion.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func foo6(a : A) {
2929

3030
func foo7(b : [B]) {}
3131
func foo8(a : [A]) {
32-
foo7(b : a) // expected-error {{cannot convert value of type '[A]' to expected argument type '[B]'}} {{13-13= as! [B]}}
32+
// TODO(diagnostics): Since `A` and `B` are related it would make sense to suggest forced downcast.
33+
foo7(b : a) // expected-error {{cannot convert value of type '[A]' to expected argument type '[B]'}}
34+
// expected-note@-1 {{arguments to generic parameter 'Element' ('A' and 'B') are expected to be equal}}
3335
}
3436

3537
protocol P1 {}

branches/master-next/test/expr/cast/array_bridge.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var b: [B] = []
3939
a = b as [A]
4040

4141
b = a // expected-error {{cannot assign value of type '[A]' to type '[B]'}}
42+
// expected-note@-1 {{arguments to generic parameter 'Element' ('A' and 'B') are expected to be equal}}
4243

4344
var aa: [[A]] = []
4445
var bb: [[B]] = []
@@ -76,6 +77,7 @@ var f: [F] = []
7677

7778
e = f as [E]
7879
f = e // expected-error {{cannot assign value of type '[E]' to type '[F]'}}
80+
// expected-note@-1 {{arguments to generic parameter 'Element' ('E' and 'F') are expected to be equal}}
7981

8082
class G {
8183
var x = 0
@@ -126,3 +128,4 @@ var i: [I] = []
126128

127129
aoa = i as [AnyObject]
128130
i = aoa // expected-error {{cannot assign value of type '[AnyObject]' to type '[I]'}}
131+
// expected-note@-1 {{arguments to generic parameter 'Element' ('AnyObject' and 'I') are expected to be equal}}

branches/master-next/test/expr/cast/array_coerce.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var da: Array<D> = [d1]
1717

1818
ca = da
1919
da = ca // expected-error{{cannot assign value of type 'Array<C>' to type 'Array<D>'}}
20+
// expected-note@-1 {{arguments to generic parameter 'Element' ('C' and 'D') are expected to be equal}}
2021

2122
var caa = [ca]
2223
var daa = [da]
@@ -29,6 +30,7 @@ var das: [D] = [d1]
2930

3031
cas = das
3132
das = cas // expected-error{{cannot assign value of type '[C]' to type '[D]'}}
33+
// expected-note@-1 {{arguments to generic parameter 'Element' ('C' and 'D') are expected to be equal}}
3234

3335
// ArraySlice<T>
3436
var cs = ca[0...0]

branches/master-next/test/expr/closure/anonymous.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ func variadic() {
3434
let _: (Int...) -> () = {takesIntArray($0)}
3535
// expected-error@-1 {{cannot convert value of type '([Int]) -> ()' to specified type '(Int...) -> ()'}}
3636

37+
// TODO(diagnostics): This requires special handling - variadic vs. array
3738
takesVariadicGeneric({takesIntArray($0)})
3839
// expected-error@-1 {{cannot convert value of type 'Array<Element>' to expected argument type '[Int]'}}
40+
// expected-note@-2 {{arguments to generic parameter 'Element' ('Element' and 'Int') are expected to be equal}}
3941

4042
takesVariadicGeneric({let _: [Int] = $0})
4143
// expected-error@-1 {{cannot convert value of type '(_) -> ()' to expected argument type '(_...) -> ()'}}

branches/master-next/test/type/subclass_composition.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ protocol P1 {
44
typealias DependentInConcreteConformance = Self
55
}
66

7-
class Base<T> : P1 {
7+
class Base<T> : P1 { // expected-note {{arguments to generic parameter 'T' ('String' and 'Int') are expected to be equal}}
88
typealias DependentClass = T
99

1010
required init(classInit: ()) {}
@@ -302,11 +302,11 @@ func conformsToAnyObject<T : AnyObject>(_: T) {}
302302
func conformsToP1<T : P1>(_: T) {}
303303
func conformsToP2<T : P2>(_: T) {}
304304
func conformsToBaseIntAndP2<T : Base<Int> & P2>(_: T) {}
305-
// expected-note@-1 {{where 'T' = 'Base<String>'}}
306-
// expected-note@-2 2 {{where 'T' = 'Base<Int>'}}
305+
// expected-note@-1 {{where 'T' = 'FakeDerived'}}
306+
// expected-note@-2 {{where 'T' = 'Base<Int>'}}
307307

308308
func conformsToBaseIntAndP2WithWhereClause<T>(_: T) where T : Base<Int> & P2 {}
309-
// expected-note@-1 {{where 'T' = 'Base<String>'}}
309+
// expected-note@-1 {{where 'T' = 'FakeDerived'}}
310310
// expected-note@-2 {{where 'T' = 'Base<Int>'}}
311311

312312
class FakeDerived : Base<String>, P2 {
@@ -421,16 +421,15 @@ func conformsTo<T1 : P2, T2 : Base<Int> & P2>(
421421
conformsToBaseIntAndP2(base)
422422
// expected-error@-1 {{argument type 'Base<Int>' does not conform to expected type 'P2'}}
423423

424-
// TODO(diagnostics): Diagnostic for this problem should mention both `Base<String>` not conforming to `P2`
425-
// and invalid generic parameter (Int vs. String)
426424
conformsToBaseIntAndP2(badBase)
427-
// expected-error@-1 {{global function 'conformsToBaseIntAndP2' requires that 'Base<Int>' conform to 'P2'}}
425+
// expected-error@-1 {{argument type 'Base<Int>' does not conform to expected type 'P2'}}
426+
// expected-error@-2 {{cannot convert value of type 'Base<String>' to expected argument type 'Base<Int>'}}
428427

429428
conformsToBaseIntAndP2(fakeDerived)
430-
// expected-error@-1 {{global function 'conformsToBaseIntAndP2' requires that 'Base<String>' inherit from 'Base<Int>'}}
429+
// expected-error@-1 {{global function 'conformsToBaseIntAndP2' requires that 'FakeDerived' inherit from 'Base<Int>'}}
431430

432431
conformsToBaseIntAndP2WithWhereClause(fakeDerived)
433-
// expected-error@-1 {{global function 'conformsToBaseIntAndP2WithWhereClause' requires that 'Base<String>' inherit from 'Base<Int>'}}
432+
// expected-error@-1 {{global function 'conformsToBaseIntAndP2WithWhereClause' requires that 'FakeDerived' inherit from 'Base<Int>'}}
434433

435434
conformsToBaseIntAndP2(p2Archetype)
436435
// expected-error@-1 {{global function 'conformsToBaseIntAndP2' requires that 'Base<Int>' conform to 'P2'}}

0 commit comments

Comments
 (0)