# Bug in unary operator overloading syntax?

**URL:** <https://discourse.julialang.org/t/bug-in-unary-operator-overloading-syntax/63117>\
**Category:** General Usage\
**Created:** [June 17, 2021, 10:31pm UTC](https://discourse.julialang.org/t/bug-in-unary-operator-overloading-syntax/63117 "2021-06-17T22:31:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [June 17, 2021, 10:31pm UTC](https://discourse.julialang.org/t/bug-in-unary-operator-overloading-syntax/63117/1 "2021-06-17T22:31:10Z")

</div>

Why doesn’t the following code work? I’m using Julia 1.6.1

```
struct MyNumber
    value::Number
end
import Base.-
-(a::MyNumber)::MyNumber = MyNumber(-a.value)

ERROR: syntax: "a::MyNumber" is not a valid function argument name around 
REPL[3]:1
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

```

The error disappears if I remove the type annotation for the return value, i.e. changing the last line to

```
-(a::MyNumber) = MyNumber(-a.value)

```

Is there a good reason for this behavior?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 17, 2021, 11:04pm UTC](https://discourse.julialang.org/t/bug-in-unary-operator-overloading-syntax/63117/2 "2021-06-17T23:04:25Z")

</div>

To define functions for operators, you often have to quote them to avoid the parsing ambiguity of _defining_ them vs. _calling_ them:

```julia
Base.:-(a::MyNumber)::MyNumber = MyNumber(-a.value)

```
