Swift 3 (Xcode 8b5): "parameters may not have the 'var' specifier"

So I'm stuck on this error in one of my projects:


"parameters may not have the 'var' specifier"


I assume this is referring to the use of 'var' in a function's arguments like:


func foobar(bast: String, var blah: Int) {


Which is now invalid in Swift 3...


The trouble is that Xcode gives me no file, line number, or other context. It seems to **** out on a particular class, but I've carefully audited that class (and all the other code in my project) and I can't find a single case where I'm using var like that. Is there some other new situation where 'var' is forbidden in Swift 3 that this might be complaining about?


Anyone have any ideas how I can go about finding & fixing this issue?

Accepted Reply

OK, finally fixed it.


This looks like its a bad error message at minimum, and probably an Xcode bug.


In case anyone else is hitting this issue, here's my situation... it might help others solve it:


I have a type with:

class NodeUpdateStream {

    typealias Operation = (inout NodeConfig) -> Bool


I was calling this with:

let stream = NodeUpdateStream(operation: { (inout node: NodeConfig) -> Bool in
   ...


And Xcode 8 "converted" this to:

let stream = NodeUpdateStream(operation: { (node: NodeConfig) -> Bool in
   ...


Instead of:

let stream = NodeUpdateStream(operation: { (node: inout NodeConfig) -> Bool in
   ...


As you can see, there are at least 3 problems here:

  • The bug "parameters may not have the 'var' specifier" is at very best misleading
  • The migrator didn't properly convert the position of 'inout', instead removing it altogether
  • The fact that the above didn't produce any line errors is problematic



Side Note: In my original post, the forums replaced "c o n v e r t e r" into "********".... ***?

Replies

So you're talking about an error shown in the issues navigator that has no corresponding "live" error in the source code?


Did you try expanding the build transcript (in the report navigator, the rightmost icon, not the build navigator)? Any error should show the source code line there.


Have you also checked protocols for any 'var' parameter specifications? You might not see that by looking at the class to which the error apparently refers.

OK, finally fixed it.


This looks like its a bad error message at minimum, and probably an Xcode bug.


In case anyone else is hitting this issue, here's my situation... it might help others solve it:


I have a type with:

class NodeUpdateStream {

    typealias Operation = (inout NodeConfig) -> Bool


I was calling this with:

let stream = NodeUpdateStream(operation: { (inout node: NodeConfig) -> Bool in
   ...


And Xcode 8 "converted" this to:

let stream = NodeUpdateStream(operation: { (node: NodeConfig) -> Bool in
   ...


Instead of:

let stream = NodeUpdateStream(operation: { (node: inout NodeConfig) -> Bool in
   ...


As you can see, there are at least 3 problems here:

  • The bug "parameters may not have the 'var' specifier" is at very best misleading
  • The migrator didn't properly convert the position of 'inout', instead removing it altogether
  • The fact that the above didn't produce any line errors is problematic



Side Note: In my original post, the forums replaced "c o n v e r t e r" into "********".... ***?