Skip to content

Commit 6e33329

Browse files
authored
Merge pull request #81193 from gottesmm/pr-5722431d23d74cb6adc74e1305c2b9e8b8d5159d
[concurrency] Fix an off by one error in generic handling in local capture checking code.
2 parents 594f46c + fb3c710 commit 6e33329

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,7 @@ namespace {
30403040
// If the local function is generic and this is one of its generic
30413041
// parameters, ignore it.
30423042
if (genericSig.getNextDepth() > 0 &&
3043-
genericDepth < genericSig.getNextDepth() - 1)
3043+
genericDepth >= genericSig.getNextDepth())
30443044
continue;
30453045

30463046
if (type->isTypeParameter() && innermostGenericDC)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
// REQUIRES: concurrency
4+
5+
struct MyType<T: Sendable> : Sendable {
6+
enum MyError: Error {
7+
case error
8+
}
9+
10+
public init(_ h: T) { self.handler = h }
11+
12+
public var handler: T
13+
14+
public func handle<OperationInput, OperationOutput>(
15+
forOperation operationID: String,
16+
using handlerMethod: @Sendable @escaping (T)
17+
-> ((OperationInput) async throws -> OperationOutput),
18+
deserializer: @Sendable @escaping (
19+
) throws -> OperationInput,
20+
serializer: @Sendable @escaping (OperationOutput) throws
21+
-> ()
22+
) async throws -> () where OperationInput: Sendable,
23+
OperationOutput: Sendable
24+
{
25+
@Sendable
26+
func wrappingErrors<R>(
27+
work: () async throws -> R,
28+
mapError: (any Error) -> any Error
29+
) async throws -> R {
30+
fatalError()
31+
}
32+
@Sendable
33+
func makeError(
34+
input: OperationInput? = nil,
35+
output: OperationOutput? = nil,
36+
error: any Error
37+
) -> any Error {
38+
fatalError()
39+
}
40+
var next: @Sendable () async throws // expected-warning {{}}
41+
-> () = {
42+
let input: OperationInput = try await wrappingErrors {
43+
try deserializer()
44+
} mapError: { error in
45+
makeError(error: error)
46+
}
47+
let output: OperationOutput = try await wrappingErrors {
48+
let method = handlerMethod(handler)
49+
return try await wrappingErrors {
50+
try await method(input)
51+
} mapError: { error in
52+
MyError.error
53+
}
54+
} mapError: { error in
55+
makeError(input: input, error: error)
56+
}
57+
return try await wrappingErrors {
58+
try serializer(output)
59+
} mapError: { error in
60+
makeError(input: input, output: output, error: error)
61+
}
62+
}
63+
return try await next()
64+
}
65+
}

0 commit comments

Comments
 (0)