swiftswift3.2

Swift 3.2 - compiler doesn't let me use the Darwin.kevent global function


This was working in Swift 3.1, however once I switched to Xcode 9 it stopped compiling. Here's a sample code:

let kq: Int32 = 0
let changelist: UnsafePointer<kevent>! = nil
let nchanges: Int32 = 0
let eventlist: UnsafeMutablePointer<kevent>! = nil
let nevents: Int32 = 0
let timeout: UnsafePointer<timespec>! = nil
Darwin.kevent(kq, changelist, nchanges, eventlist, nevents, timeout)

Error is

error: missing argument labels 'ident:filter:flags:fflags:data:udata:' in call

The problems seems to be caused by the fact that the Darwin module exports both a struct an a function with the same name - kevent, and the compiler doesn't choose the global function and instead wants me to add the struct initializer labels, which doesn't work for me as the parameters lists don't match.

The kevent struct initalizer looks like this

public init(ident: UInt, filter: Int16, flags: UInt16, fflags: UInt32, data: Int, udata: UnsafeMutableRawPointer!)

I even tried declaring all arguments as local variables (as in the sample code), in order to make sure there is no type inference that would make the function call incorrect which could cause the compiler to think that I wanted to use the struct. No luck.

Does anybody know a solution to this "overloading" issue?


Solution

  • I cannot tell you why the fully qualified function name does not compile with Swift 3.2, but

    kevent(kq, changelist, nchanges, eventlist, nevents, timeout)
    

    without the Darwin prefix compiles without problems (tested with Xcode 9 GM, Swift 3.2 and Swift 4).

    I can confirm that

    Darwin.kevent(kq, changelist, nchanges, eventlist, nevents, timeout)
    

    compiles with Swift 3.1 (Xcode 8.3.3), so you might want to file a bug report.