Skip to content

Commit e3655f5

Browse files
committed
[CSApply] Perform a regular coerceToType when adjusting types for
preconcurrency.
1 parent e4436ba commit e3655f5

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/Sema/CSApply.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ namespace {
645645
cs.cacheType(declRefExpr);
646646
declRefExpr->setFunctionRefKind(choice.getFunctionRefKind());
647647
Expr *result = adjustTypeForDeclReference(
648-
declRefExpr, fullType, adjustedFullType);
648+
declRefExpr, fullType, adjustedFullType, locator);
649649
result = forceUnwrapIfExpected(result, locator);
650650

651651
if (auto *fnDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
@@ -925,6 +925,7 @@ namespace {
925925
/// conversions. This can happen due to `@preconcurrency`.
926926
Expr *adjustTypeForDeclReference(
927927
Expr *expr, Type openedType, Type adjustedOpenedType,
928+
ConstraintLocatorBuilder locator,
928929
llvm::function_ref<Type(Type)> getNewType = [](Type type) {
929930
return type;
930931
}) {
@@ -960,16 +961,16 @@ namespace {
960961

961962
expr = new (context) BindOptionalExpr(expr, SourceLoc(), 0, objectType);
962963
cs.cacheType(expr);
963-
expr = adjustTypeForDeclReference(expr, objectType, adjustedObjectType);
964+
expr = adjustTypeForDeclReference(
965+
expr, objectType, adjustedObjectType, locator);
964966
expr = new (context) InjectIntoOptionalExpr(expr, adjustedRefType);
965967
cs.cacheType(expr);
966968
expr = new (context) OptionalEvaluationExpr(expr, adjustedRefType);
967969
cs.cacheType(expr);
968970
return expr;
969971
}
970972

971-
assert(false && "Unhandled adjustment");
972-
return expr;
973+
return coerceToType(expr, adjustedOpenedType, locator);
973974
}
974975

975976
/// Determines if a partially-applied member reference should be
@@ -1539,7 +1540,7 @@ namespace {
15391540
Expr *ref = cs.cacheType(new (context) DotSyntaxBaseIgnoredExpr(
15401541
base, dotLoc, dre, refTy));
15411542

1542-
ref = adjustTypeForDeclReference(ref, refTy, adjustedRefTy);
1543+
ref = adjustTypeForDeclReference(ref, refTy, adjustedRefTy, locator);
15431544
return forceUnwrapIfExpected(ref, memberLocator);
15441545
}
15451546

@@ -1685,7 +1686,7 @@ namespace {
16851686

16861687
// Adjust the declaration reference type, if required.
16871688
ref = adjustTypeForDeclReference(
1688-
ref, openedType, adjustedOpenedType, computeRefType);
1689+
ref, openedType, adjustedOpenedType, locator, computeRefType);
16891690

16901691
closeExistentials(ref, locator, /*force=*/openedExistential);
16911692

@@ -1732,7 +1733,8 @@ namespace {
17321733

17331734
Expr *result = memberRefExpr;
17341735
result = adjustTypeForDeclReference(result, resultType(refTy),
1735-
resultType(adjustedRefTy));
1736+
resultType(adjustedRefTy),
1737+
locator);
17361738
closeExistentials(result, locator);
17371739

17381740
// If the property is of dynamic 'Self' type, wrap an implicit
@@ -1764,7 +1766,7 @@ namespace {
17641766
cs.setType(declRefExpr, refTy);
17651767
Expr *ref = declRefExpr;
17661768

1767-
ref = adjustTypeForDeclReference(ref, refTy, adjustedRefTy);
1769+
ref = adjustTypeForDeclReference(ref, refTy, adjustedRefTy, locator);
17681770

17691771
// A partial application thunk consists of two nested closures:
17701772
//
@@ -1941,7 +1943,8 @@ namespace {
19411943
apply = ConstructorRefCallExpr::create(context, ref, base);
19421944
} else if (isUnboundInstanceMember) {
19431945
ref = adjustTypeForDeclReference(
1944-
ref, cs.getType(ref), cs.simplifyType(adjustedOpenedType));
1946+
ref, cs.getType(ref), cs.simplifyType(adjustedOpenedType),
1947+
locator);
19451948

19461949
// Reference to an unbound instance method.
19471950
Expr *result = new (context) DotSyntaxBaseIgnoredExpr(base, dotLoc,

test/SILGen/preconcurrency.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ func testInstanceMethodWithSendable(c: C, any: Any) {
2727
let _ = C.g
2828
c.f(any)
2929
}
30+
31+
class Request {
32+
@preconcurrency let identifier: (any Sendable)? = nil
33+
}
34+
35+
func test(from request: Request) {
36+
// Make sure we don't assert in CSApply when adjusting 'any Sendable' -> 'Any'
37+
// for preconcurrency
38+
let _ = request.identifier
39+
}

0 commit comments

Comments
 (0)