Function-like with unnamed parameter

IDE: Visual Studio X/Fire
Version: 10.0.0.2399 (develop)
Target (If relevant): OSX
Description:
Using _ as an external name, but providing no internal name should be allowed.
This provides internal documentation that one does not use that parameter, and
in protocols, the internal name is merely a suggestion for the implementor.

Expected Behavior:
Compiles, one cannot use the parameter (non-protocol).
Actual Behavior:
“E: identifier expected, got wildcard [<file> (<line>)]”
Steps:

func(_: String) {}
// or:
protocol P {
  func(_: String)
}

Thanks, logged as bugs://82599

jesus wept… who came up with this language… :wink:

1 Like

bugs://82599 got closed with status fixed.

One related case: externally named, internally unnamed parameter.

func foo<T>(from _: T.Type) { // colon expected
  // Use T (not the value of T.Type)
}

Why would one use this?
Because the (standard) Swift compiler forbids explicitly specializing generic functions, generic functions must explicitly take or return a value which can select the generic’s value. In absence of any other alternative T.Type may be used.
However, such parameters may not need to be named internally, but may be named externally.


Edit: also the parser does not like explicitly removing the external name of the first parameter:

func foo(_ bar: Int) { // identifier expected, got wildcard
  // 
}

jesus wept. :wink:

1 Like

Thanks, logged as bugs://82625

bugs://82625 got closed with status fixed.