In Swift you can find out from where your function was called by providing the default arguments #file
and #line
, like so:
func myFunc(x : T, y : T, file : String = #file, line : Int = #line) -> T {
print("Being called at \(file):\(line)")
return someComputation(x, y)
}
Is it somehow possible to achieve the same for (infix) operators? Direct translation of the above doesn't work:
func == (x : T, y : T, file : String = #file, line : Int = #line) -> T {
print("Being called at \(file):\(line)")
return someComputation(x, y)
}
will predictably give an error along the lines of "operators must have one or two arguments".
My concrete problem is that I have a DSL which uses infix operators, and I would like to know where those infix operators were called for better error messages.