Skip to content

Commit 773d327

Browse files
authored
Merge pull request #84798 from slavapestov/fix-rdar162130647
Sema: Fix concurrency adjustment for member operator references
2 parents 5846e8f + 359bd4d commit 773d327

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ using namespace inference;
4343

4444
#define DEBUG_TYPE "ConstraintSystem"
4545

46-
47-
4846
Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
4947
Type parentTy,
5048
ConstraintLocatorBuilder locator,
@@ -1235,38 +1233,37 @@ ConstraintSystem::getTypeOfReferencePost(OverloadChoice choice,
12351233
auto *value = choice.getDecl();
12361234

12371235
if (value->getDeclContext()->isTypeContext() && isa<FuncDecl>(value)) {
1238-
auto *openedFnType = openedType->castTo<FunctionType>();
1239-
12401236
// Unqualified lookup can find operator names within nominal types.
12411237
auto func = cast<FuncDecl>(value);
12421238
assert(func->isOperator() && "Lookup should only find operators");
12431239

12441240
auto functionRefInfo = choice.getFunctionRefInfo();
12451241

1246-
auto origOpenedType = openedFnType;
1242+
auto origOpenedType = openedType;
12471243
if (!isRequirementOrWitness(locator)) {
12481244
unsigned numApplies = getNumApplications(/*hasAppliedSelf*/ false,
12491245
functionRefInfo);
1250-
openedFnType = adjustFunctionTypeForConcurrency(
1251-
origOpenedType, /*baseType=*/Type(), func, useDC, numApplies,
1252-
/*isMainDispatchQueue=*/false, /*openGlobalActorType=*/true, locator);
1246+
openedType = adjustFunctionTypeForConcurrency(
1247+
origOpenedType->castTo<FunctionType>(), /*baseType=*/Type(),
1248+
func, useDC, numApplies, /*isMainDispatchQueue=*/false,
1249+
/*openGlobalActorType=*/true, locator);
12531250
}
12541251

12551252
// If this is a method whose result type is dynamic Self, replace
12561253
// DynamicSelf with the actual object type. Repeat the adjustment
12571254
// for the original and adjusted types.
1258-
auto type = openedFnType;
1259-
if (openedFnType->hasDynamicSelfType()) {
1260-
auto params = openedFnType->getParams();
1255+
auto type = openedType;
1256+
if (openedType->hasDynamicSelfType()) {
1257+
auto params = openedType->castTo<FunctionType>()->getParams();
12611258
assert(params.size() == 1);
12621259
Type selfTy = params.front().getPlainType()->getMetatypeInstanceType();
1263-
type = openedFnType->replaceDynamicSelfType(selfTy)
1260+
type = openedType->replaceDynamicSelfType(selfTy)
12641261
->castTo<FunctionType>();
12651262
}
12661263

12671264
auto origType = origOpenedType;
12681265
if (origOpenedType->hasDynamicSelfType()) {
1269-
auto params = origOpenedType->getParams();
1266+
auto params = origOpenedType->castTo<FunctionType>()->getParams();
12701267
assert(params.size() == 1);
12711268
Type selfTy = params.front().getPlainType()->getMetatypeInstanceType();
12721269
origType = origOpenedType->replaceDynamicSelfType(selfTy)
@@ -1275,7 +1272,8 @@ ConstraintSystem::getTypeOfReferencePost(OverloadChoice choice,
12751272

12761273
// The reference implicitly binds 'self'.
12771274
return {origOpenedType, openedType,
1278-
origType->getResult(), type->getResult(), Type()};
1275+
origType->castTo<FunctionType>()->getResult(),
1276+
type->castTo<FunctionType>()->getResult(), Type()};
12791277
}
12801278

12811279
// Unqualified reference to a local or global function.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -dump-ast -swift-version 6 %s | %FileCheck %s
2+
3+
// CHECK: (func_decl decl_context={{.*}} range={{.*}} "test(v:)"
4+
func test<T: Equatable>(v: T) {
5+
// CHECK: (function_conversion_expr implicit type="@Sendable (T.Type) -> (T, T) -> Bool"
6+
_ = v == v
7+
}

0 commit comments

Comments
 (0)