Function-like with unnamed parameter

(Dante Broggi) #1

IDE: Visual Studio X/Fire
Version: (develop)
Target (If relevant): OSX
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>)]”

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

Thanks, logged as bugs://82599

(marc hoffman) #3

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

1 Like
(RemObjects) #4

bugs://82599 got closed with status fixed.

(Dante Broggi) #5

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
(marc hoffman) #6

jesus wept. :wink:

1 Like
(RemObjects) #7

Thanks, logged as bugs://82625

(RemObjects) #8

bugs://82625 got closed with status fixed.