-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.expressionsFeature: expressionsFeature: expressionstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Description
A function definition that relies on Type inference from default expression (SE-0347) compiles when it's defined inside a type (a method), but does't compile when it's defined as a free function.
Reproduction
As a method, this compiles:
struct MyTask {
func sleep<C: Clock>(
until deadline: C.Instant,
clock: C = ContinuousClock()
) async throws {}
}
But: the same function signature as a free function doesn't compile:
func sleep<C: Clock>(
until deadline: C.Instant,
// ❌: Cannot use default expression for inference of 'C'
// because it is inferrable from parameters #0, #1
clock: C = ContinuousClock()
) async throws {}
Expected behavior
The free function should compile.
Environment
macOS 14.3, Xcode 15.3 (Swift 5.10)
$ swift --version
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Additional information
Forum thread where this is being discussed: https://forums.swift.org/t/type-inference-from-default-expression-doesnt-compile-in-free-function/70521/3
lachenmayer, ph1ps and ahmdmhasn
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.expressionsFeature: expressionsFeature: expressionstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis