eclipse-xtext / eclipse-xtext/xtext

Implementing operator_plus(Float left, Number right)

Open
#2,248 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

I've just started a discussion here about implementing operator_plus(Float, Number) in FloatExtensions

To be quick, I noticed DoubleExtensions provides a method to add a Double and a Number with the operator +. I'd like to have the same for Float implemented like this:

@Pure
public static double operator_plus(Float a, Number b) {
return a + b.doubleValue();
}

But when I do it in my own FloatExtensions class, it does not work (instead of using the method I define, it seems it tries to cast Number to a byte, in order to call another + operator).

So:

  • Is there a reason operator_plus(Float, Number) is not defined in FloatExtensions?
  • Why is my implementation not working? (Note: if I use, for instance, AtomicDouble instead of Number, it works fine, it fails only when the argument is Number)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with FloatExtensions and DoubleExtensions, then read the linked forum discussion to understand why Number dispatch differs from AtomicDouble. Done means deciding whether operator_plus(Float, Number) belongs in FloatExtensions and implementing or documenting the expected + behavior, with relevant project tests updated as appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.