Hi All,

I'm trying the following code where i'm trying to overload "+" operator with lhs and rhs of different types and returning a new type as a return value.

```
import Foundation
struct e {
let index:Int
}
extension e {
init(_ x:Int) {
index = x
}
}
struct GeometricNumber {
let e:e
let coefficient:Float
}
extension GeometricNumber : CustomDebugStringConvertible {
var debugDescription: String {
"\(coefficient)*e(\(e.index))"
}
}
precedencegroup eProccessOrder {
associativity:left
higherThan: AdditionPrecedence
}
infix operator *:eProccessOrder
func * (_ coeff:Float, _ es:e) -> GeometricNumber {
GeometricNumber(e: es,coefficient: coeff)
}
func * (_ es:e,_ coeff:Float) -> GeometricNumber {
GeometricNumber(e: es,coefficient: coeff)
}
enum MathOperations {
case addition,substraction,multiplication,division
}
struct GeometricExpression {
var expression:[(GeometricNumber, MathOperations)]
}
extension GeometricExpression:CustomDebugStringConvertible {
var debugDescription: String {
return self.expression.map { (first:GeometricNumber, second:MathOperations) -> String in
return "\(first) \(operation(second))"
}.joined(separator: " ")
}
}
func operation(_ op:MathOperations) -> String {
switch op {
case .addition:
return "+"
case .substraction:
return "-"
case .multiplication:
return "*"
case .division:
return "/"
}
}
precedencegroup geometricExpressions {
associativity:left
}
infix operator +:geometricExpressions
func + (_ lhs:GeometricNumber, _ rhs:GeometricNumber) -> GeometricExpression {
var exp = [(GeometricNumber, MathOperations)]()
exp.append((lhs,.addition))
exp.append((rhs,.addition))
return GeometricExpression(expression: exp)
}
func + (_ lhs:GeometricExpression, _ rhs:GeometricNumber) -> GeometricExpression {
var exp = [(GeometricNumber, MathOperations)]()
exp.append(contentsOf: lhs.expression)
exp.append((rhs, .addition))
return GeometricExpression(expression: exp)
}
func + (_ lhs:GeometricNumber, _ rhs:GeometricExpression) -> GeometricExpression {
var exp = [(GeometricNumber, MathOperations)]()
exp.append((lhs, .addition))
exp.append(contentsOf: rhs.expression)
return GeometricExpression(expression: exp)
}
let g1 = 10*e(1)
let g2 = 20*e(2)
let g3 = 3.2*e(3)
g1 + g2 // This works fine
g1 + g2 + g3 // This gives compiler error.
```

**here is the code where > 1 chaining has issues**

```
g1 + g2 // This works fine
g1 + g2 + g3 // This gives compiler error.
```

**here is the error**

```
expression failed to parse:
error: pga.playground:101:9: error: cannot convert value of type 'GeometricExpression' to expected argument type 'GeometricNumber'
g1 + g2 + g3
^
error: pga.playground:101:11: error: cannot convert value of type 'GeometricNumber' to expected argument type 'GeometricExpression'
g1 + g2 + g3
^
```

I'm not sure if there is any constraint for operator overloading to have lhs and rhs of same type? here "+" operator is just an example I have faced similar issues for many other operators too. Is there any way to hint the compiler to pick the next possible one? Any inputs will be helpful.