Custom operator woes

What am I doing wrong?

4> prefix operator ~~
5> prefix func ~~ (_ input: any BinaryInteger) { print(String(input, radix: 2)) }
˄
╰─ error: operator implementation without matching operator declaration

5> :version
lldb version 17.0.0 (
 revision 901f89886dcd5d1eaf07c8504d58c90f37b0cfdf)
Apple Swift version 6.1 (swift-6.1-RELEASE)

Yeah, I know I could just make a regular function, but I want to see if this would work.

Copy-pasting this into swift.godbolt.org works fine for me

Huh, I just terminated my repl and started it again, and now it’s fine.

That suggests something in this mess terminally confused the repl:

06:54 $ swift repl
Welcome to Apple Swift version 6.1 (swift-6.1-RELEASE).
Type :help for assistance.
  1> operator prefix ,,
              ˄
              ╰─ error: expected operator name in operator declaration
  1> prefix operator ,,
                     ˄
                     ╰─ error: ',' is not allowed in operator names
  1> prefix operator ~~
  2> func ~~ (_ input: BinaryIn
Available completions:
        BinaryIn -- .Type: <<error type>>.Type
        BinaryIn -- BinaryInteger
  2> func ~~ (_ input: BinaryIntger) { print(String(input, radix: 2)) }
          ˄            ˄˜˜˜˜˜˜˜˜˜˜˜
          │            ╰─ error: cannot find type 'BinaryIntger' in scope
          ╰─ error: unary operator implementation must have a 'prefix' or 'postfix' modifier
  2> func prefix ~~ (_ input: BinaryInteger) { print(String(input, radix: 2)) }
                ˄˄     ˄                    ˄˄
                ││     │                    │╰─ error: top-level statement cannot begin with a closure expression
                ││     │                    ╰─ error: consecutive statements on a line must be separated by ';'
                ││     ╰─ error: expected ',' separator
                │╰─ error: expected '(' in argument list of function declaration
                │╰─ error: unary operator cannot be separated from its operand
                ╰─ error: consecutive statements on a line must be separated by ';'
  2> prefix func ~~ (_ input: BinaryInteger) { print(String(input, radix: 2)) }
                 ˄            ˄
                 │            ╰─ warning: use of protocol 'BinaryInteger' as a type must be written 'any BinaryInteger'; this will be an error in a future Swift language mode
                 ╰─ error: operator implementation without matching operator declaration
  2> static prefix func ~~ (_ input: any BinaryInteger) { print(String(input, radix: 2)) }
                   ˄
                   ╰─ error: static methods may only be declared on a type
  2> prefix func ~~ (_ input: any BinaryInteger) { print(String(input, radix: 2)) }
                 ˄
                 ╰─ error: operator implementation without matching operator declaration
  2>
  3> prefix operator ~~
  4> prefix func ~~ (_ input: any BinaryInteger) { print(String(input, radix: 2)) }
                 ˄
                 ╰─ error: operator implementation without matching operator declaration
  4> prefix operator ~~
  5> prefix func ~~ (_ input: any BinaryInteger) { print(String(input, radix: 2)) }
                 ˄
                 ╰─ error: operator implementation without matching operator declaration
  5> prefix func ~~(_ input: any BinaryInteger) { print(String(input, radix: 2)) }
                 ˄
                 ╰─ error: operator implementation without matching operator declaration
  5> ?
     ˄
     ╰─ error: expected expression
  5> :version
lldb version 17.0.0 (https://github.com/swiftlang/llvm-project.git revision 901f89886dcd5d1eaf07c8504d58c90f37b0cfdf)
Apple Swift version 6.1 (swift-6.1-RELEASE)

Sometimes when the repl gets confused, I find I have to put them on the same line. i.e. prefix operator ~~ ; prefix func ~~ ... with a semicolon instead of a line break.