You can read a nice explanation of leaf variables in this post 1.1k.
Usually you have to avoid modifying a leaf variable with an in-place operation.
I haven’t seen your error message yet, but it seems it related to an in-place modification, because you are re-assigning the values of W in this line:
W[0]=w1 * w2; W[1]=w2 * w3; W[2]=w3 * w1