Don't offer incorrect fixit for NSString? -> String? conversion.

Update the locator when matching optional types in parallel fashion.
This causes the simplifyLocator() call to fail to simplify the locator
completely, and avoids the bogus diagnostic.

<rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions

Swift SVN r25596
This commit is contained in:
Chris Willmore
2015-02-27 05:30:11 +00:00
parent e7140012bf
commit 9910c75c67
2 changed files with 13 additions and 2 deletions

View File

@@ -3684,7 +3684,9 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
assert(generic2->getDecl()->classifyAsOptionalType());
return matchTypes(generic1->getGenericArgs()[0],
generic2->getGenericArgs()[0],
matchKind, subFlags, locator);
matchKind, subFlags,
locator.withPathElement(
LocatorPathElt::getGenericArgument(0)));
}
// T <c U ===> T! <c U
@@ -3705,7 +3707,9 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
Type valueType1 = boundGenericType1->getGenericArgs()[0];
increaseScore(SK_ForceUnchecked);
return matchTypes(valueType1, type2,
matchKind, subFlags, locator);
matchKind, subFlags,
locator.withPathElement(
LocatorPathElt::getGenericArgument(0)));
}
case ConversionRestrictionKind::ClassMetatypeToAnyObject:

View File

@@ -233,3 +233,10 @@ func rdar19831698() {
var v73 = true + [] // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'NSArray'}}
var v75 = true + "str" // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'String'}} expected-note{{}}
}
// <rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions
func rdar19836341(s: NSString?) {
let x: String? = s // expected-error{{'NSString?' is not convertible to 'String?'}}
// FIXME: there should be a fixit appending "as String?" to the line; for now
// it's sufficient that it doesn't suggest appending "as String"
}