You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all,
this is not really an issue of the compiler. C# does it the same. But something worth to discuss.
I got
error XS0563: One of the parameters of a binary operator must be the containing type
when defining ++ operator to classes derived from interface.
on the commented code below.
Interesting: a missing != operator gives warning
warning XS0216: The operator 'FrankMaraite.SimplePoint.operator ==(FrankMaraite.ISimplePoint, FrankMaraite.ISimplePoint)' requires a matching operator '!=' to also be defined
Of course, this operator, when added, is also not allowed.
The C# (5) compiler doen't allow this too. A solution may be to have my own method like IsSamePositon() in this case.
Or let the compiler call the == operator on the left class. Hm ... confusing. Maybe this is something for the new C# compiler with standard implemantions of interfaces.
Here a small sample together with test code:
`INTERFACE ISimplePoint
PROPERTY East AS REAL8 GET SET
PROPERTY North AS REAL8 GET SET
METHOD Equals( point AS ISimplePoint ) AS LOGIC
END INTERFACE
CLASS SimplePoint IMPLEMENTS ISimplePoint, IEquatable
PROPERTY East AS REAL8 AUTO
PROPERTY North AS REAL8 AUTO
PUBLIC OVERRIDE METHOD Equals( point AS ISimplePoint ) AS LOGIC
IF !( point IS SimplePoint )
RETURN FALSE
ELSE
IF SELF:East == point:East ;
.AND.SELF:North == point:North
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDIF
OPERATOR == ( point1 AS SimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( point2 )
END OPERATOR
OPERATOR == ( point1 AS SimplePoint, point2 AS ISimplePoint ) AS LOGIC
RETURN point1:Equals( Point2 )
END OPERATOR
OPERATOR == ( point1 AS ISimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( Point2 )
END OPERATOR
OPERATOR == ( point1 AS ISimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( point2 )
END OPERATOR
// OPERATOR == ( point1 AS ISimplePoint, point2 AS ISimplePoint ) AS LOGIC
// RETURN point1:Equals( point2 )
// END OPERATOR
END CLASS
`
The commented lines are not allowed. Now the tests:
`
[Test] ;
METHOD Gleich_TRUE_IP AS VOID STRICT
LOCAL Point AS ISimplePoint
Point := SimplePoint{ 1.0, 2.0, 3.0 }
LOCAL Point2 AS SimplePoint
Point2 := SimplePoint{ 1.0, 2.0, 3.0 }
Assert.That( Point == Point2, Is.True )
[Test] ;
METHOD Gleich_TRUE_PI AS VOID STRICT
LOCAL Point AS SimplePoint
Point := SimplePoint{ 1.0, 2.0, 3.0 }
LOCAL Point2 AS ISimplePoint
Point2 := SimplePoint{ 1.0, 2.0, 3.0 }
Assert.That( Point == Point2, Is.True )
[Test] ;
METHOD Gleich_TRUE_PP AS VOID STRICT
LOCAL Point AS SimplePoint
Point := SimplePoint{ 1.0, 2.0, 3.0 }
LOCAL Point2 AS SimplePoint
Point2 := SimplePoint{ 1.0, 2.0, 3.0 }
Assert.That( Point == Point2, Is.True )
[Test] ;
METHOD Gleich_TRUE_II AS VOID STRICT
LOCAL Point AS ISimplePoint // <---
Point := SimplePoint{ 1.0, 2.0, 3.0 }
LOCAL Point2 AS ISimplePoint // <---
Point2 := SimplePoint{ 1.0, 2.0, 3.0 }
Assert.That( Point == Point2, Is.True )
`
The last test fails, because the local variable is declared as interface. And there is no == operator for.
Hope, this was clear.
Wish you a merry christmas and a happy new year
Frank
The text was updated successfully, but these errors were encountered:
Hi all,
this is not really an issue of the compiler. C# does it the same. But something worth to discuss.
I got
error XS0563: One of the parameters of a binary operator must be the containing type
when defining ++ operator to classes derived from interface.
on the commented code below.
Interesting: a missing != operator gives warning
warning XS0216: The operator 'FrankMaraite.SimplePoint.operator ==(FrankMaraite.ISimplePoint, FrankMaraite.ISimplePoint)' requires a matching operator '!=' to also be defined
Of course, this operator, when added, is also not allowed.
The C# (5) compiler doen't allow this too. A solution may be to have my own method like IsSamePositon() in this case.
Or let the compiler call the == operator on the left class. Hm ... confusing. Maybe this is something for the new C# compiler with standard implemantions of interfaces.
Here a small sample together with test code:
`INTERFACE ISimplePoint
PROPERTY East AS REAL8 GET SET
PROPERTY North AS REAL8 GET SET
METHOD Equals( point AS ISimplePoint ) AS LOGIC
END INTERFACE
CLASS SimplePoint IMPLEMENTS ISimplePoint, IEquatable
PROPERTY East AS REAL8 AUTO
PROPERTY North AS REAL8 AUTO
PUBLIC OVERRIDE METHOD Equals( point AS ISimplePoint ) AS LOGIC
OPERATOR == ( point1 AS SimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( point2 )
END OPERATOR
OPERATOR == ( point1 AS SimplePoint, point2 AS ISimplePoint ) AS LOGIC
RETURN point1:Equals( Point2 )
END OPERATOR
OPERATOR == ( point1 AS ISimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( Point2 )
END OPERATOR
OPERATOR == ( point1 AS ISimplePoint, point2 AS SimplePoint ) AS LOGIC
RETURN point1:Equals( point2 )
END OPERATOR
// OPERATOR == ( point1 AS ISimplePoint, point2 AS ISimplePoint ) AS LOGIC
// RETURN point1:Equals( point2 )
// END OPERATOR
END CLASS
`
The commented lines are not allowed. Now the tests:
`
[Test] ;
METHOD Gleich_TRUE_IP AS VOID STRICT
[Test] ;
METHOD Gleich_TRUE_PI AS VOID STRICT
LOCAL Point AS SimplePoint
Point := SimplePoint{ 1.0, 2.0, 3.0 }
[Test] ;
METHOD Gleich_TRUE_PP AS VOID STRICT
[Test] ;
METHOD Gleich_TRUE_II AS VOID STRICT
`
The last test fails, because the local variable is declared as interface. And there is no == operator for.
Hope, this was clear.
Wish you a merry christmas and a happy new year
Frank
The text was updated successfully, but these errors were encountered: