Skip to content

Commit 99e72b6

Browse files
[TypeCheckConstraints] Check for archetypes when warning about unrelated type conversion
1 parent 164ebbf commit 99e72b6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,9 +3706,11 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
37063706
else
37073707
fromRequiresClass = fromType->mayHaveSuperclass();
37083708

3709-
// Casts between protocol metatypes only succeed if the type is existential.
3709+
// Casts between protocol metatypes only succeed if the type is existential
3710+
// or if it involves generic types because they may be protocol conformances
3711+
// we can't know at compile time.
37103712
if (metatypeCast) {
3711-
if (toExistential || fromExistential)
3713+
if ((toExistential || fromExistential) && !(fromArchetype || toArchetype))
37123714
return failed();
37133715
}
37143716

0 commit comments

Comments
 (0)