Skip to content

Commit 4b8bd6a

Browse files
committed
Sema: Fix diagnoseConformanceImpliedByConditionalConformance() for tuple conformances
1 parent 653c00c commit 4b8bd6a

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,13 +1901,12 @@ void MultiConformanceChecker::checkAllConformances() {
19011901
static void diagnoseConformanceImpliedByConditionalConformance(
19021902
DiagnosticEngine &Diags, NormalProtocolConformance *conformance,
19031903
NormalProtocolConformance *implyingConf, bool issueFixit) {
1904-
Type T = conformance->getType();
19051904
auto proto = conformance->getProtocol();
19061905
Type protoType = proto->getDeclaredInterfaceType();
19071906
auto implyingProto = implyingConf->getProtocol()->getDeclaredInterfaceType();
19081907
auto loc = implyingConf->getLoc();
19091908
Diags.diagnose(loc, diag::conditional_conformances_cannot_imply_conformances,
1910-
T, implyingProto, protoType);
1909+
conformance->getType(), implyingProto, protoType);
19111910

19121911
if (!issueFixit)
19131912
return;
@@ -1949,11 +1948,7 @@ static void diagnoseConformanceImpliedByConditionalConformance(
19491948
llvm::raw_svector_ostream prefixStream(prefix);
19501949
llvm::raw_svector_ostream suffixStream(suffix);
19511950

1952-
ValueDecl *decl = T->getAnyNominal();
1953-
if (!decl)
1954-
decl = T->getAnyGeneric();
1955-
1956-
prefixStream << "extension " << decl->getName() << ": " << protoType << " ";
1951+
prefixStream << "extension " << ext->getExtendedType() << ": " << protoType << " ";
19571952
suffixStream << " {\n"
19581953
<< indent << extraIndent << "<#witnesses#>\n"
19591954
<< indent << "}\n\n"

test/Generics/tuple-conformances.swift

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,45 @@
33
// Because of -enable-experimental-feature TupleConformances
44
// REQUIRES: asserts
55

6+
extension () {
7+
// expected-error@-1 {{tuple extension must be written as extension of '(repeat each Element)'}}
8+
// expected-error@-2 {{tuple extension must declare conformance to exactly one protocol}}
9+
}
10+
11+
typealias Tuple<each Element> = (repeat each Element)
12+
13+
protocol Q {}
14+
15+
class C {}
16+
17+
extension Tuple: Q where repeat each Element: Collection, repeat (each Element).Element == (each Element).Index, repeat (each Element).Indices: AnyObject, repeat (each Element).SubSequence: C {}
18+
// expected-error@-1 {{tuple extension must require that 'each Element' conforms to 'Q'}}
19+
// expected-error@-2 {{tuple extension cannot require that 'each Element' conforms to 'Collection'}}
20+
// expected-error@-3 {{tuple extension cannot require that '(each Element).Element' is the same type as '(each Element).Index'}}
21+
// expected-error@-4 {{tuple extension cannot require that '(each Element).Indices' conforms to 'AnyObject'}}
22+
// expected-error@-5 {{tuple extension cannot require that '(each Element).SubSequence' subclasses 'C'}}
23+
24+
protocol Base1 {}
25+
protocol Derived1: Base1 {}
26+
27+
extension Tuple: Derived1 where repeat each Element: Derived1 {}
28+
// expected-error@-1 {{conditional conformance of type '(repeat each Element)' to protocol 'Derived1' does not imply conformance to inherited protocol 'Base1'}} // FIXME: crappy error
29+
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension (repeat each Element): Base1 where ...'?}}
30+
// expected-error@-3 {{tuple extension must declare conformance to exactly one protocol}}
31+
32+
protocol Base2 {}
33+
protocol Derived2: Base2 {}
34+
35+
extension Tuple: Derived2 {}
36+
// expected-error@-1 {{tuple extension must declare conformance to exactly one protocol}} // FIXME: crappy error
37+
638
protocol P {
739
associatedtype A
840
associatedtype B
941

1042
func f()
1143
}
1244

13-
extension () {}
14-
// expected-error@-1 {{tuple extension must be written as extension of '(repeat each Element)'}}
15-
// FIXME: Inaccurate
16-
17-
typealias Tuple<each Element> = (repeat each Element)
18-
1945
extension Tuple: P where repeat each Element: P {
2046
typealias A = (repeat (each Element).A)
2147
typealias B = Float

0 commit comments

Comments
 (0)