Skip to content

Commit cd283b1

Browse files
authored
Merge pull request #3813 from jckarter/tuple-bridging
Sema: Gratuitously wrap synthesized bridging calls in ParenExprs.
2 parents bc08704 + a6c05f3 commit cd283b1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,15 +1517,24 @@ namespace {
15171517
auto valueSub = Substitution(valueType, {});
15181518
auto bridgeAnythingRef = ConcreteDeclRef(tc.Context, bridgeAnything,
15191519
valueSub);
1520+
auto valueParenTy = ParenType::get(tc.Context, value->getType());
15201521
auto bridgeTy = tc.Context.getProtocol(KnownProtocolKind::AnyObject)
15211522
->getDeclaredType();
1522-
auto bridgeFnTy = FunctionType::get(valueType, bridgeTy);
1523+
auto bridgeFnTy = FunctionType::get(valueParenTy, bridgeTy);
1524+
// FIXME: Wrap in ParenExpr to prevent bogus "tuple passed as argument"
1525+
// errors.
1526+
auto valueParen = new (tc.Context) ParenExpr(SourceLoc(),
1527+
value,
1528+
SourceLoc(),
1529+
/*trailing closure*/ false);
1530+
valueParen->setImplicit();
1531+
valueParen->setType(valueParenTy);
15231532
auto fnRef = new (tc.Context) DeclRefExpr(bridgeAnythingRef,
15241533
DeclNameLoc(),
15251534
/*implicit*/ true,
15261535
AccessSemantics::Ordinary,
15271536
bridgeFnTy);
1528-
Expr *call = CallExpr::createImplicit(tc.Context, fnRef, value,
1537+
Expr *call = CallExpr::createImplicit(tc.Context, fnRef, valueParen,
15291538
{ Identifier() });
15301539
call->setType(bridgeTy);
15311540
return call;

test/Constraints/bridging.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,9 @@ func bridgeAnyContainerToAnyObject(x: [Any], y: [NSObject: Any]) {
359359

360360
_ = z
361361
}
362+
363+
func bridgeTupleToAnyObject() {
364+
let x = (1, "two")
365+
let y = x as AnyObject
366+
_ = y
367+
}

0 commit comments

Comments
 (0)