Skip to content

Commit 933075d

Browse files
[CSFix] Add check to dont diagnose if has SubExpressionDiagnostics flag
1 parent 60ab6db commit 933075d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/Sema/CSFix.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,11 @@ bool RemoveUnnecessaryCoercion::attempt(ConstraintSystem &cs, Type fromType,
11501150
if (ctx.LangOpts.DisableRedundantCoercionWarning)
11511151
return false;
11521152

1153+
// Don't diagnose if this is coming from a CSDiag typecheck subExpr diagnostics.
1154+
// We can remove this once CSDiag is gone.
1155+
if (cs.Options.contains(ConstraintSystemFlags::SubExpressionDiagnostics))
1156+
return false;
1157+
11531158
auto last = locator.last();
11541159
bool isExplicitCoercion =
11551160
last && last->is<LocatorPathElt::ExplicitTypeCoercion>();
@@ -1168,10 +1173,6 @@ bool RemoveUnnecessaryCoercion::attempt(ConstraintSystem &cs, Type fromType,
11681173
if (!fromType->isEqual(castType) && !castType->hasTypeVariable())
11691174
return false;
11701175

1171-
// Fixed type was already applied to the subEpxr.
1172-
if (expr->getSubExpr()->getType())
1173-
return false;
1174-
11751176
auto toTypeRepr = expr->getCastTypeLoc().getTypeRepr();
11761177

11771178
// Don't emit this diagnostic for Implicitly unwrapped optional types

test/expr/cast/as_coerce.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ c3 as C4 // expected-error {{'C3' is not convertible to 'C4'; did you mean to us
8181
// <rdar://problem/19495142> Various incorrect diagnostics for explicit type conversions
8282
1 as Double as Float // expected-error{{cannot convert value of type 'Double' to type 'Float' in coercion}}
8383
1 as Int as String // expected-error{{cannot convert value of type 'Int' to type 'String' in coercion}}
84-
Double(1) as Double as String // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}} expected-warning {{redundant cast to 'Double' has no effect}} {{11-21=}}
84+
Double(1) as Double as String // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}}
8585
["awd"] as [Int] // expected-error{{cannot convert value of type 'String' to expected element type 'Int'}}
8686
([1, 2, 1.0], 1) as ([String], Int)
8787
// expected-error@-1 2 {{cannot convert value of type 'Int' to expected element type 'String'}}

0 commit comments

Comments
 (0)