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

operators are not found if the parameters are not exactly the same as the arguments #49

Open
wietlol opened this issue Jul 18, 2017 · 1 comment

Comments

@wietlol
Copy link

wietlol commented Jul 18, 2017

Consider the following scenario:

public class Test
{
    public void foo()
    {
        A a = new A();
        B b = new B();
        
        Base c = a & b; // << "Operator '&' cannot be applied to 'A', 'B'"
        c = a.and(b);
        c = a + b; // << "Operator '+' cannot be applied to 'A', 'B'"
        c = a.add(b);
    }
}

class A implements Base { }

class B implements Base { }

interface Base
{
    default Base and(Base other) { return this;  }
    default Base add(Base other) { return this; }
}

As you might imagine, the functional syntax works fine as "a" implements Base so it has the and/add methods and "b" implements Base so it is a valid parameter.
But the operator syntax cannot recognize them as valid operators.

If I change the parameters from Base to B, it works fine.
Or if I change the variable "B b" to "Base b", it also works fine.
The same also happens if Base is a class.

However, I have 16 classes that all have to be able to use the "and" operator on each other.
And that would result in 16*15 methods with all duplicate code that could very well be in one interface.

I am using IntelliJ Ultimate version 2017.2 with the Java-oo plugin 0.6.
(Javac compiler)

@yuemingl
Copy link

yuemingl commented Jul 18, 2017

This issue is the same as the issue #29. I can confirm that this exists only in IntelliJ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants