Skip to content

[4.0] Escalate the warning about the "== Self" type soundness hole to an error #10320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1416,11 +1416,6 @@ ERROR(witness_self_same_type,none,
" (in protocol %5) due to same-type requirement involving 'Self'",
(DescriptiveDeclKind, DeclName, Type, DescriptiveDeclKind,
DeclName, Type))
WARNING(witness_self_same_type_warn,none,
"%0 %1 in non-final class %2 cannot be used to satisfy requirement %3 %4"
" (in protocol %5) due to same-type requirement involving 'Self'",
(DescriptiveDeclKind, DeclName, Type, DescriptiveDeclKind,
DeclName, Type))
NOTE(witness_self_weaken_same_type,none,
"consider weakening the same-type requirement %0 == %1 to a superclass "
"requirement", (Type, Type))
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3121,9 +3121,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
auto proto = Conformance->getProtocol();
auto &diags = proto->getASTContext().Diags;
diags.diagnose(witness->getLoc(),
proto->getASTContext().LangOpts.isSwiftVersion3()
? diag::witness_self_same_type_warn
: diag::witness_self_same_type,
diag::witness_self_same_type,
witness->getDescriptiveKind(),
witness->getFullName(),
Conformance->getType(),
Expand Down
7 changes: 6 additions & 1 deletion test/Compatibility/self_same_type.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// RUN: %target-typecheck-verify-swift -swift-version 3

// Note: while Swift 3.2 originally intended to provide backward
// compatibility here, the type-soundness issue was considered so severe
// (due to it breaking the optimizer) that that we escalated it to an
// error.

protocol P {
associatedtype T
}
Expand All @@ -9,7 +14,7 @@ protocol Q {
}

class C1: Q {
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'}}}}
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'}}}}
// expected-note@-1{{consider weakening the same-type requirement 'T.T' == 'C1' to a superclass requirement}}{{41-43=:}}
}

Expand Down