[swift-evolution] [Proposal Draft] parameter forwarding

Chris Lattner clattner at apple.com
Mon Jan 11 19:53:15 CST 2016

On Jan 10, 2016, at 7:44 PM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
> Proposed solution
> The proposed solution is to introduce an automatic parameter forwarding mechansim. It allows users to provide direct arguments for some parameters while forwarding others.
> The basic mechanism looks like this:
> func foo(i i: Int, s: String, f: Float = 42, d: Double = 43, b: Bool = false) { }
> // user writes:
> func bar(...fooParams) {
>     foo(i: 32, ...fooParams)
> }
> // compiler synthesizes:
> func bar(s: String, f: Float = 42, d: Double = 43, b: Bool = false) {
>     foo(i: 32, s: s, f: f, d: d, b: b)
> }
This approach is extremely problematic and unlikely to be accepted.

Swift is carefully designed so that the compiler can type check the interface to a function without type checking its body.  This is important for compiler scalability to large projects, IDE tooling, and also because otherwise you can run into circular dependencies to compile the code.

Another major problem with this approach is that it only works if “foo” is unambiguous.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160111/24af3fdb/attachment.html>

More information about the swift-evolution mailing list