Skip to content

Sema: Gratuitously wrap synthesized bridging calls in ParenExprs. #3813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,15 +1517,24 @@ namespace {
auto valueSub = Substitution(valueType, {});
auto bridgeAnythingRef = ConcreteDeclRef(tc.Context, bridgeAnything,
valueSub);
auto valueParenTy = ParenType::get(tc.Context, value->getType());
auto bridgeTy = tc.Context.getProtocol(KnownProtocolKind::AnyObject)
->getDeclaredType();
auto bridgeFnTy = FunctionType::get(valueType, bridgeTy);
auto bridgeFnTy = FunctionType::get(valueParenTy, bridgeTy);
// FIXME: Wrap in ParenExpr to prevent bogus "tuple passed as argument"
// errors.
auto valueParen = new (tc.Context) ParenExpr(SourceLoc(),
value,
SourceLoc(),
/*trailing closure*/ false);
valueParen->setImplicit();
valueParen->setType(valueParenTy);
auto fnRef = new (tc.Context) DeclRefExpr(bridgeAnythingRef,
DeclNameLoc(),
/*implicit*/ true,
AccessSemantics::Ordinary,
bridgeFnTy);
Expr *call = CallExpr::createImplicit(tc.Context, fnRef, value,
Expr *call = CallExpr::createImplicit(tc.Context, fnRef, valueParen,
{ Identifier() });
call->setType(bridgeTy);
return call;
Expand Down
6 changes: 6 additions & 0 deletions test/Constraints/bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,9 @@ func bridgeAnyContainerToAnyObject(x: [Any], y: [NSObject: Any]) {

_ = z
}

func bridgeTupleToAnyObject() {
let x = (1, "two")
let y = x as AnyObject
_ = y
}