Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opertator ++ (and maybe others) on interface #291

Open
FrankMaraite opened this issue Dec 24, 2019 · 1 comment
Open

opertator ++ (and maybe others) on interface #291

FrankMaraite opened this issue Dec 24, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@FrankMaraite
Copy link

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

@RobertvanderHulst RobertvanderHulst added this to the Later milestone Dec 30, 2019
@RobertvanderHulst RobertvanderHulst modified the milestones: Later, March 2020 Mar 2, 2020
@RobertvanderHulst RobertvanderHulst modified the milestones: April 2020, May 2020 May 2, 2020
@RobertvanderHulst RobertvanderHulst modified the milestones: May 2020, June 2020 Jun 5, 2020
@RobertvanderHulst RobertvanderHulst removed this from the August 2020 milestone Apr 8, 2021
@RobertvanderHulst
Copy link
Member

This will only work in .Net Core and .Net 5. We will add support for this when we have completed the .Net Core support for VS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: To do
Development

No branches or pull requests

2 participants