Default expression for inference works for static methods but not functions #67680
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
declarations
Feature: declarations
default arguments
Feature: default arguments for value parameters
func
Feature → declarations: Functions
generics
Feature: generic declarations and types
swift 5.9
type checker
Area → compiler: Semantic analysis
type inference
Feature: type inference
unexpected error
Bug: Unexpected error
Description
A default expression for type inference of a protocol when another parameter is an associated type of the protocol works for static methods but not functions.
Consider Task.sleep:
This method has a generic type
C
constrained toClock
, and it's parameters use both the typesC
andC.Instant
.C
is inferred from the clock parameter's the default expressionContinousClock()
.Task.sleep
is inexpressible as a function, even though no type information fromTask
is required—Task
is strictly used as a namespace. As far as I know, static methods should be expressible as functions as long as they don't depend on anything from the type.Steps to reproduce
Here's a minimal example using a default expression for inference of a protocol in a static method and as a function, with the function failing to compile:
The function
defaulting
fails to compile with the message,Cannot use default expression for inference of 'P' because it is inferrable from parameters #0, #1
.Expected behavior
I'd expect to be able to express functions the same as static methods such as
Task.sleep
and, from the example above,Namespace.defaulting
.Environment
swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
The text was updated successfully, but these errors were encountered: