Skip to content

Commit 55b3acc

Browse files
authored
Merge pull request #10319 from DougGregor/escalate-type-soundness-warning
Escalate the warning about the "== Self" type soundness hole to an error
2 parents 088e4cd + 8b80681 commit 55b3acc

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,11 +1420,6 @@ ERROR(witness_self_same_type,none,
14201420
" (in protocol %5) due to same-type requirement involving 'Self'",
14211421
(DescriptiveDeclKind, DeclName, Type, DescriptiveDeclKind,
14221422
DeclName, Type))
1423-
WARNING(witness_self_same_type_warn,none,
1424-
"%0 %1 in non-final class %2 cannot be used to satisfy requirement %3 %4"
1425-
" (in protocol %5) due to same-type requirement involving 'Self'",
1426-
(DescriptiveDeclKind, DeclName, Type, DescriptiveDeclKind,
1427-
DeclName, Type))
14281423
NOTE(witness_self_weaken_same_type,none,
14291424
"consider weakening the same-type requirement %0 == %1 to a superclass "
14301425
"requirement", (Type, Type))

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,9 +3122,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
31223122
auto proto = Conformance->getProtocol();
31233123
auto &diags = proto->getASTContext().Diags;
31243124
diags.diagnose(witness->getLoc(),
3125-
proto->getASTContext().LangOpts.isSwiftVersion3()
3126-
? diag::witness_self_same_type_warn
3127-
: diag::witness_self_same_type,
3125+
diag::witness_self_same_type,
31283126
witness->getDescriptiveKind(),
31293127
witness->getFullName(),
31303128
Conformance->getType(),

test/Compatibility/self_same_type.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %target-typecheck-verify-swift -swift-version 3
22

3+
// Note: while Swift 3.2 originally intended to provide backward
4+
// compatibility here, the type-soundness issue was considered so severe
5+
// (due to it breaking the optimizer) that that we escalated it to an
6+
// error.
7+
38
protocol P {
49
associatedtype T
510
}
@@ -9,7 +14,7 @@ protocol Q {
914
}
1015

1116
class C1: Q {
12-
func foo<T: P>(_: T, _: C1) where T.T == C1 {} // expected-warning{{instance method 'foo' in non-final class 'C1' cannot be used to satisfy requirement instance method 'foo' (in protocol 'Q') due to same-type requirement involving 'Self'}}}}
17+
func foo<T: P>(_: T, _: C1) where T.T == C1 {} // expected-error{{instance method 'foo' in non-final class 'C1' cannot be used to satisfy requirement instance method 'foo' (in protocol 'Q') due to same-type requirement involving 'Self'}}}}
1318
// expected-note@-1{{consider weakening the same-type requirement 'T.T' == 'C1' to a superclass requirement}}{{41-43=:}}
1419
}
1520

0 commit comments

Comments
 (0)