consulo / consulo-csharp

Languages: C#
Apache License 2.0
50 stars 6 forks source link

Wrong short→int/float overload resolution causes false-positive syntax error #526

Open NIA opened 6 years ago

NIA commented 6 years ago

Consider the following code:

public class Temp {

    public void foo() {
        // uses int overload, ok
        int a = f(1, 2);

        // uses int overload, again ok
        int b = f(1, (short)2);

        // uses float overload (and shows "cannot cast float to int" error): WRONG, should still use int overload
        int c = f((short) 1, (short)2);
    }

    public static float f(float a, float b) {
        return a + b;
    }

    public static int f(int a, int b) {
        return a + b;
    }
}

In all three cases the f(int a, int b) overload is selected by compiler (because int is better conversion target from short than float).

But Consulo makes the wrong decision: in third case it decides to use f(float, float) overload (it is easy to check this by ctrl+clicking on method call) and this causes it to think that the assignment of the result to c is error: image But this is not correct: the given piece of code compiles without warnings.

P.S. actually I noticed this issue with the given piece of code:

   int random = UnityEngine.Random.Range(short.MaxValue/2, short.MaxValue);

It is similar because Random.Range indeed has two overloads: one for (int,int)->int and one for (float,float)->float. But as you see above, the issue is not relevant for Consulo's Unity integration, that's why I'm reporting it here.

VISTALL commented 6 years ago

Hi. You are right about repository. Thanks for bug

VISTALL commented 6 years ago

Hello. It's priority bug(change f method positions, and will be ok), i am thinking about fix, but not easy. Thanks