Skip to content

Commit 3fdb42f

Browse files
authored
Upstream bug fix related to keyword argument dynamic callable. (#26322)
1 parent fda6115 commit 3fdb42f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6818,8 +6818,10 @@ ExprRewriter::finishApplyDynamicCallable(const Solution &solution,
68186818
cs.setType(labelExpr, keyType);
68196819
handleStringLiteralExpr(cast<LiteralExpr>(labelExpr));
68206820

6821-
Expr *pair =
6822-
TupleExpr::createImplicit(ctx, { labelExpr, arg->getElement(i) }, {});
6821+
Expr *valueExpr = coerceToType(arg->getElement(i), valueType, loc);
6822+
if (!valueExpr)
6823+
return nullptr;
6824+
Expr *pair = TupleExpr::createImplicit(ctx, {labelExpr, valueExpr}, {});
68236825
auto eltTypes = { TupleTypeElt(keyType), TupleTypeElt(valueType) };
68246826
cs.setType(pair, TupleType::get(eltTypes, ctx));
68256827
dictElements.push_back(pair);

test/SILGen/dynamic_callable_attribute.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ public func foo(a: Callable) {
2424
// CHECK: [[DYN_CALL_2:%.*]] = function_ref @$s26dynamic_callable_attribute8CallableV15dynamicallyCall13withArgumentsySaySiG_tF
2525
// CHECK-NEXT: apply [[DYN_CALL_2]]
2626
// CHECK: [[DYN_CALL_3:%.*]] = function_ref @$s26dynamic_callable_attribute8CallableV15dynamicallyCall20withKeywordArgumentsys13KeyValuePairsVySSSiG_tF
27+
28+
29+
@dynamicCallable
30+
public struct Callable2 {
31+
func dynamicallyCall(withKeywordArguments: KeyValuePairs<String, Any>) {}
32+
}
33+
34+
// CHECK-LABEL: sil [ossa] @keywordCoerceBug
35+
// CHECK:[[DYN_CALL:%.*]] = function_ref @$s26dynamic_callable_attribute9Callable2V15dynamicallyCall20withKeywordArgumentsys13KeyValuePairsVySSypG_tF
36+
37+
@_silgen_name("keywordCoerceBug")
38+
public func keywordCoerceBug(a: Callable2, s: Int) {
39+
a(s)
40+
}

0 commit comments

Comments
 (0)