Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Operator == with null operand
Operator == with null operand [message #1795053] Thu, 13 September 2018 11:53 Go to next message
Eclipse UserFriend
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 12:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi I don't know any option for that
Re: Operator == with null operand [message #1795055 is a reply to message #1795054] Thu, 13 September 2018 12:06 Go to previous messageGo to next message
Eclipse UserFriend
You may open a bug at xtext-extras to discuss this with Sebastian
Re: Operator == with null operand [message #1795059 is a reply to message #1795055] Thu, 13 September 2018 14:42 Go to previous messageGo to next message
Eclipse UserFriend
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 14:53 Go to previous message
Eclipse UserFriend
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: Mon Jun 16 08:02:05 EDT 2025

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

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

Back to the top