File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -4146,6 +4146,12 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
4146
4146
if (superclass)
4147
4147
MinimalMembers.insert (MinimalMembers.begin (), superclass->getCanonicalType ());
4148
4148
4149
+ // If we are left with a single member and no layout constraint, the member
4150
+ // is the minimal type. Also, note that a protocol composition cannot be
4151
+ // constructed with a single member unless there is a layout constraint.
4152
+ if (MinimalMembers.size () == 1 && !MinimalHasExplicitAnyObject)
4153
+ return CanType (MinimalMembers.front ());
4154
+
4149
4155
// The resulting composition is necessarily canonical.
4150
4156
return CanType (build (Ctx, MinimalMembers, MinimalHasExplicitAnyObject));
4151
4157
}
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ typealias OtherAndP2 = Other & P2
42
42
43
43
protocol P3 : class { }
44
44
45
+ protocol P4 { }
46
+
45
47
struct Unrelated { }
46
48
47
49
//
@@ -70,6 +72,18 @@ func alreadyConforms(_: P3 & AnyObject) {} // expected-error {{invalid redeclara
70
72
func alreadyConformsMeta( _: P3 . Type ) { } // expected-note {{'alreadyConformsMeta' previously declared here}}
71
73
func alreadyConformsMeta( _: ( P3 & AnyObject ) . Type) { } // expected-error {{invalid redeclaration of 'alreadyConformsMeta'}}
72
74
75
+ func notARedeclaration( _: P4 ) { }
76
+ func notARedeclaration( _: P4 & AnyObject ) { }
77
+
78
+ do {
79
+ class C : P4 { }
80
+ struct S < T: P4 > {
81
+ // Don't crash when computing minimal compositions inside a generic context.
82
+ func redeclaration( _: C & P4 ) { } // expected-note {{'redeclaration' previously declared here}}
83
+ func redeclaration( _: C & P4 ) { } // expected-error {{invalid redeclaration of 'redeclaration'}}
84
+ }
85
+ }
86
+
73
87
// SE-0156 stipulates that a composition can contain multiple classes, as long
74
88
// as they are all the same.
75
89
func basicDiagnostics(
You can’t perform that action at this time.
0 commit comments