Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Operator == with null operand
Operator == with null operand [message #1795053] Thu, 13 September 2018 15:53 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear all.

I have defined several extension methods (which are implicitly imported):
def boolean operator_equals(AtomicLong left, int right) {}
def boolean operator_equals(AtomicLong left, short right) {}
def boolean operator_equals(AtomicLong left, long right) {}
def boolean operator_equals(AtomicLong left, float right) {}
def boolean operator_equals(AtomicLong left, double right) {}
def boolean operator_equals(AtomicLong left, byte right) {}
def boolean operator_equals(AtomicLong left, Number right) {}
def boolean operator_equals(AtomicInteger left, int right) {}
def boolean operator_equals(AtomicInteger left, short right) {}
def boolean operator_equals(AtomicInteger left, long right) {}
def boolean operator_equals(AtomicInteger left, float right) {}
def boolean operator_equals(AtomicInteger left, double right) {}
def boolean operator_equals(AtomicInteger left, byte right) {}
def boolean operator_equals(AtomicInteger left, Number right) {}


The following line is compiled without error:
def void fct(AtomicInteger value) {
  if (value == null) {
  }
}


But the following line causes a compilation error (ambiguous feature call):
def void fct(AtomicInteger value) {
  if (null == value) {
  }
}


As you could see, the operands of the == operator are switched.
Semantically, both definitions are equivalent.

My question is: what is the best way to support the failing case?

Is possible to define an operator_equals function and specifying that this function is usable when the left argument is null?

Should I define operator_equals(Object left, Number right)? In this case, the type compiler of Xbase hould be fixed to avoid the ambiguous feature call error.

What do you think?

All the best.
Stéphane.
Re: Operator == with null operand [message #1795054 is a reply to message #1795053] Thu, 13 September 2018 16:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi I don't know any option for that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Operator == with null operand [message #1795055 is a reply to message #1795054] Thu, 13 September 2018 16:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You may open a bug at xtext-extras to discuss this with Sebastian

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Operator == with null operand [message #1795059 is a reply to message #1795055] Thu, 13 September 2018 18:42 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear Christian.

Thank you for your answer.

Discussion is open here.

Stéphane.
Re: Operator == with null operand [message #1795060 is a reply to message #1795059] Thu, 13 September 2018 18:53 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

IIRC The Xtend ==/!= semantics evolved requiring use of ===/!== to avoid warnings on null tests.

Unless you have weird semantics that require null to go through your custom routines, why not just use ===?

Regards

Ed Willink
Previous Topic:Syntax for bitwise AND operator
Next Topic:Testing the Syntax/Semantic highlights
Goto Forum:
  


Current Time: Wed Apr 24 16:36:56 GMT 2024

Powered by FUDForum. Page generated in 0.03525 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top