[swift-evolution] SE-0031 and Swift 2

Drew Crawford drew at sealedabstract.com
Sat Apr 16 05:55:15 CDT 2016


Hello,

I'm writing to complain about SE-0031 and Swift 2 compatibility.  I understand (and agree with!) the change, but the migration between now and 2017 is annoying, hence my complaint.

In snapshot swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a, we started erroring on the old syntax.  That means that this:

    func foo(inout bar: Int) { }

is not legal Swift 3.

...however, the new syntax:

    func foo(bar: inout Int) { }

is not legal Swift 2.  This complicates compiling for both, which several of my projects currently do.

/Further complicating matters/, Swift does not understand line-scoped ifdefs.  So this:

    #if swift(>=3.0)
        func foo(bar: inout Int) {
    #else
        func foo(inout bar: Int) {
    #endif
        //my
            //long
            //functon
            //definition
    }

Is not legal Swift.  The only way I know of is to say:

    #if swift(>=3.0)
        func foo(bar: inout Int) {
                //my
                //long
                //functon
                //definition
        }
    #else
        func foo(inout bar: Int) {
                //my
                //long
                //functon
                //definition
        }
    #endif

which forces duplication of the entire function definition.

My suggestion would be one or more of the following:

1.  Support both syntaxes in Swift 3 "trunk" (e.g. until Swift 3 is released).
2.  Backport the new syntax to Swift 2.2
3.  Consider allowing line-scoped ifdefs

Thanks for reading, and sorry to rain on a parade I largely think is Good For Swift ™

Drew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160416/3c74ca7d/attachment.html>


More information about the swift-evolution mailing list