Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
There are some minor discrepancies in how Groovy is dealing with overloading for unaryMinus and unaryPlus with numbers. Here is one example:
class IntCat { static unaryPlus(Integer i) {"P"} static unaryMinus(Integer i) {"M"} } use (IntCat) { println 1.unaryPlus() // => P println 1.unaryMinus() // => M println (+1) // => 1 println (-1) // => -1 }
We either need to not bypass operator overriding or document the reasons why we want a special case here.
And here is another:
println 1.unaryMinus() // => -1 println 1.unaryPlus() // => MME unaryPlus
We should provide the same hook for both (or potentially not provide this for either and provide documentation to justify why a special case would be needed).
Note also that it is a little strange for Strings too.
def foo = 'foo' println (-foo) // => MME negative println (+foo) // => MME positive