Skip to content

Commit

Permalink
Don't allow silent failures in protocol conformances.
Browse files Browse the repository at this point in the history
As of r31224, we tried to suppress redundant protocol-conformance
diagnostics for witnesses that look like they could have matched
something in an unconstrained protocol extension. However, this was
allowing ill-formed conformances to be accepted, causing a crash in
the AST verifier. Fixes rdar://problem/23033862.

Swift SVN r32671
  • Loading branch information
DougGregor committed Oct 13, 2015
1 parent fa3bb96 commit 4b82904
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,9 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
// If there was an invalid witness that might have worked, just
// suppress the diagnostic entirely. This stops the diagnostic cascade.
// FIXME: We could do something crazy, like try to fix up the witness.
if (invalidWitness || (numViable == 0 && anyFromUnconstrainedExtension)) {
if (invalidWitness ||
(numViable == 0 && anyFromUnconstrainedExtension &&
Conformance->isInvalid())) {
return ResolveWitnessResult::ExplicitFailed;
}

Expand Down
14 changes: 11 additions & 3 deletions test/decl/protocol/conforms/failure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,25 @@ struct P5Conformer : P5 { // expected-error {{does not conform}}
protocol P6Base {
typealias Foo
func foo()
func bar() -> Foo
func bar() -> Foo // expected-note{{protocol requires function 'bar()' }}
}
extension P6Base {
}
protocol P6 : P6Base {
typealias Bar // expected-note {{protocol requires nested type 'Bar'}}
}
extension P6 {
func bar() -> Bar? { return nil }
func bar() -> Bar? { return nil } // expected-note{{candidate has non-matching type}}
}

struct P6Conformer : P6 { // expected-error {{does not conform}}
struct P6Conformer : P6 { // expected-error 2 {{does not conform}}
func foo() {}
}

// rdar://problem/23033862
// expected-error@+2{{type 'A' does not conform to protocol 'OptionSetType'}}
// expected-error@+1{{type 'A' does not conform to protocol 'RawRepresentable'}}
struct A: OptionSetType {
let rawValue = 0
init() { } // expected-note 2{{candidate has non-matching type '()'}}
}

0 comments on commit 4b82904

Please sign in to comment.