Skip to content

[concurrency] Fix an off by one error in generic handling in local capture checking code. #81193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3040,7 +3040,7 @@ namespace {
// If the local function is generic and this is one of its generic
// parameters, ignore it.
if (genericSig.getNextDepth() > 0 &&
genericDepth < genericSig.getNextDepth() - 1)
genericDepth >= genericSig.getNextDepth())
continue;

if (type->isTypeParameter() && innermostGenericDC)
Expand Down
65 changes: 65 additions & 0 deletions test/Concurrency/metatype_crasher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: %target-typecheck-verify-swift -swift-version 6

// REQUIRES: concurrency

struct MyType<T: Sendable> : Sendable {
enum MyError: Error {
case error
}

public init(_ h: T) { self.handler = h }

public var handler: T

public func handle<OperationInput, OperationOutput>(
forOperation operationID: String,
using handlerMethod: @Sendable @escaping (T)
-> ((OperationInput) async throws -> OperationOutput),
deserializer: @Sendable @escaping (
) throws -> OperationInput,
serializer: @Sendable @escaping (OperationOutput) throws
-> ()
) async throws -> () where OperationInput: Sendable,
OperationOutput: Sendable
{
@Sendable
func wrappingErrors<R>(
work: () async throws -> R,
mapError: (any Error) -> any Error
) async throws -> R {
fatalError()
}
@Sendable
func makeError(
input: OperationInput? = nil,
output: OperationOutput? = nil,
error: any Error
) -> any Error {
fatalError()
}
var next: @Sendable () async throws // expected-warning {{}}
-> () = {
let input: OperationInput = try await wrappingErrors {
try deserializer()
} mapError: { error in
makeError(error: error)
}
let output: OperationOutput = try await wrappingErrors {
let method = handlerMethod(handler)
return try await wrappingErrors {
try await method(input)
} mapError: { error in
MyError.error
}
} mapError: { error in
makeError(input: input, error: error)
}
return try await wrappingErrors {
try serializer(output)
} mapError: { error in
makeError(input: input, output: output, error: error)
}
}
return try await next()
}
}