Skip to content

Commit 4b5be17

Browse files
Fixing check and some other tests
1 parent 7f030e0 commit 4b5be17

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/Sema/CSSimplify.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -2808,18 +2808,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28082808
// If the types are obviously equivalent, we're done.
28092809
if (desugar1->isEqual(desugar2)) {
28102810
auto locatorPtr = locator.getBaseLocator();
2811-
if (kind >= ConstraintKind::Conversion &&
2812-
locatorPtr->
2813-
isLastElement(ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2814-
if (!llvm::any_of(getFixes(), [&locatorPtr](const ConstraintFix *fix) -> bool {
2815-
if (fix->getLocator() == locatorPtr)
2816-
return true;
2817-
return fix->getLocator()->getAnchor() == locatorPtr->getAnchor();
2818-
})) {
2819-
auto *fix = RemoveUnecessaryCoercion::create(*this, type2,
2820-
locatorPtr);
2821-
recordFix(fix);
2811+
if (kind >= ConstraintKind::Conversion) {
2812+
if (locator.last().hasValue() &&
2813+
locator.last().getValue().getKind()
2814+
== ConstraintLocator::PathElementKind::ExplicityTypeCoercion) {
2815+
2816+
if (!llvm::any_of(getFixes(), [&locatorPtr](const ConstraintFix *fix) -> bool {
2817+
if (fix->getLocator() == locatorPtr)
2818+
return true;
2819+
return fix->getLocator()->getAnchor() == locatorPtr->getAnchor();
2820+
})) {
2821+
auto *fix = RemoveUnecessaryCoercion::create(*this, type2,
2822+
locatorPtr);
2823+
recordFix(fix);
2824+
}
28222825
}
2826+
28232827
}
28242828
if (!isa<InOutType>(desugar2))
28252829
return getTypeMatchSuccess();

test/Sema/diag_unintended_optional_behavior.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func warnOptionalInStringInterpolationSegment(_ o : Int?) {
212212
// expected-note@-2 {{use 'String(describing:)' to silence this warning}} {{51-51=String(describing: }} {{67-67=)}}
213213
// expected-note@-3 {{provide a default value to avoid this warning}} {{67-67= ?? <#default value#>}}
214214

215-
print("Always some, Always some, Always some: \(o as Int?)") // No warning
215+
print("Always some, Always some, Always some: \(o as Int?)") // expected-warning {{casting expression to 'Int?' doesn't change the type}} {{53-60=}}
216216
print("Always some, Always some, Always some: \(o.debugDescription)") // No warning.
217217

218218
let oST = Optional(SpecialType())

0 commit comments

Comments
 (0)