Skip to content

Commit 89ab4aa

Browse files
committed
Fix the "early" computation of a return type to respect @preconcurrency.
Fixes rdar://91087622.
1 parent a6bcd80 commit 89ab4aa

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,9 +2457,14 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
24572457
}
24582458
}
24592459

2460+
auto hasAppliedSelf =
2461+
doesMemberRefApplyCurriedSelf(overload.getBaseType(), decl);
2462+
unsigned numApplies = getNumApplications(
2463+
decl, hasAppliedSelf, overload.getFunctionRefKind());
2464+
24602465
type = adjustFunctionTypeForConcurrency(
24612466
type->castTo<FunctionType>(),
2462-
subscript, useDC, /*numApplies=*/2, /*isMainDispatchQueue=*/false)
2467+
decl, useDC, numApplies, /*isMainDispatchQueue=*/false)
24632468
->getResult();
24642469
}
24652470
}

test/Concurrency/predates_concurrency.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,29 @@ func aFailedExperiment(@_unsafeSendable _ body: @escaping () -> Void) { }
126126

127127
func anothingFailedExperiment(@_unsafeMainActor _ body: @escaping () -> Void) { }
128128
// expected-warning@-1{{'_unsafeMainActor' attribute has been removed in favor of @preconcurrency}}
129+
130+
// ---------------------------------------------------------------------------
131+
// Random bugs
132+
// ---------------------------------------------------------------------------
133+
134+
public enum StringPlacement : Sendable {
135+
public typealias StringPosition = @Sendable (_: [String]) -> Int
136+
137+
@preconcurrency
138+
public static func position(before string: String) -> StringPosition {
139+
return { _ in 0 }
140+
}
141+
142+
@preconcurrency
143+
public static func position(after string: String) -> StringPosition {
144+
return { _ in 0 }
145+
}
146+
}
147+
148+
func testStringPlacement() {
149+
let fn1 = StringPlacement.position(before: "Test")
150+
let _: Int = fn1 // expected-error{{cannot convert value of type '([String]) -> Int' to specified type 'Int'}}
151+
152+
let fn2 = StringPlacement.position(before:)
153+
let _: Int = fn2 // expected-error{{cannot convert value of type '(String) -> ([String]) -> Int' to specified type 'Int'}}
154+
}

0 commit comments

Comments
 (0)