Skip to content

Commit 49a1917

Browse files
committed
Sema: Fix bug with protocol compositions in expression context
If the left hand side was not a TypeExpr, we would just drop it on the floor instead of giving up on forming a protocol composition.
1 parent 4c1a28b commit 49a1917

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,8 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
13241324
return nullptr;
13251325
else
13261326
return nullptr;
1327-
}
1327+
} else
1328+
return nullptr;
13281329

13291330
// Add the rhs which is just a TypeExpr
13301331
auto *rhs = dyn_cast<TypeExpr>(binaryExpr->getArg()->getElement(1));

test/type/protocol_composition.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,13 @@ struct S05<T> where T : P5? & P6 {} // expected-error {{inheritance from non-nam
163163
struct S3124<T: protocol<P1, P3>> {} // expected-warning {{'protocol<...>' composition syntax is deprecated; join the protocols using '&'}} {{17-34=P1 & P3>}}
164164
func f3124_1<U where U: protocol<P1, P3>>(x: U) {} // expected-warning {{'protocol<...>' composition syntax is deprecated; join the protocols using '&'}} {{25-42=P1 & P3>}} // expected-error {{'where' clause}}
165165
func f3124_2<U : protocol<P1>>(x: U) {} // expected-warning {{'protocol<...>' composition syntax is deprecated and not needed here}} {{18-31=P1>}}
166+
167+
// Make sure we correctly form compositions in expression context
168+
func takesP1AndP2(_: [AnyObject & P1 & P2]) {}
169+
170+
takesP1AndP2([AnyObject & P1 & P2]())
171+
takesP1AndP2([Swift.AnyObject & P1 & P2]())
172+
takesP1AndP2([AnyObject & protocol_composition.P1 & P2]())
173+
takesP1AndP2([AnyObject & P1 & protocol_composition.P2]())
174+
takesP1AndP2([DoesNotExist & P1 & P2]()) // expected-error {{use of unresolved identifier 'DoesNotExist'}}
175+
takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift' has no member named 'DoesNotExist'}}

0 commit comments

Comments
 (0)