summaryrefslogtreecommitdiff
path: root/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Ambiguity.java
blob: c7f2194a151d96ffd2c71959b0d5d4a82cbaa091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package todelete;

/**
 * Created with IntelliJ IDEA.
 * User: Anna.Kozlova
 * Date: 9/26/12
 * Time: 1:18 PM
 * To change this template use File | Settings | File Templates.
 */
class MyTest {
    interface Bar1 {
        int _(String s);
    }

    interface Bar2 {
        int _(int s);
    }

    void bar(Bar1 b1){}
    void bar(Bar2 b1){}

    static int foo(int i) {
        return 0;
    }

    static int foo(String i) {
        return 0;
    }

    {
        Bar1 b1 = MyTest :: foo;
        bar<error descr="Ambiguous method call: both 'MyTest.bar(Bar1)' and 'MyTest.bar(Bar2)' match">(MyTest :: foo)</error>;
    }
}

class MyTest1 {
    interface Bar1 {
        int _(String s);
    }

    interface Bar2 {
        int _(int s);
    }

    //void bar(Bar1 b1){}
    void bar(Bar2 b1){}

    static int foo(int i) {
        return 0;
    }

    static int foo(String i) {
        return 0;
    }

    {
        <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest1.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
        bar(MyTest1 :: foo);
    }
}

class MyTest2 {
    interface Bar1 {
        int _(String s);
    }

    interface Bar2 {
        int _(int s);
    }

    void bar(Bar1 b1){}
    void bar(Bar2 b1){}

    static int foo(int i) {
        return 0;
    }

    /*static int foo(String i) {
        return 0;
    }*/

    {
        <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest2.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
        bar(MyTest2 :: foo);
    }
}

class MyTest3 {
    interface Bar1 {
        int _(String s);
    }

    interface Bar2 {
        int _(int s);
    }

    //void bar(Bar1 b1){}
    void bar(Bar2 b1){}

    /*static int foo(int i) {
        return 0;
    }*/

    static int foo(String i) {
        return 0;
    }

    {
        <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest3.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
        bar<error descr="'bar(todelete.MyTest3.Bar2)' in 'todelete.MyTest3' cannot be applied to '(<method reference>)'">(MyTest3 :: foo)</error>;
    }
}


class MyTest4 {
    interface Bar1<T> {
        int _(T s);
    }


    void bar(Bar1 b1){}

    static int foo(int i) {
        return 0;
    }

    static int foo(String i) {
        return 0;
    }

    {
         bar<error descr="'bar(todelete.MyTest4.Bar1)' in 'todelete.MyTest4' cannot be applied to '(<method reference>)'">(MyTest4:: foo)</error>;
    }
}

class MyTest5 {
    interface Bar1<T> {
        int _(T s);
    }


    static <T1> void bar(Bar1<T1> b1){}

    static <K> int foo(K k) {
        return 0;
    }

    static int foo(String i) {
        return 0;
    }

    {
         //todo ambiguity rules checked MyTest5.<String>bar(MyTest5::foo);
    }
}

class MyTest6 {
    interface I {
       void _(Integer i);
    }

    static void foo(Number i) {}
    static void foo(Integer i, String s) {}
    static void foo(Integer d) {}

    public static void main(String[] args) {
        I s = MyTest6::foo;
        s._(1);
    }
}

class MyTest7 {
    interface I {
       void _(Number i);
    }

    static void foo(Number i) {}
    static void foo(Integer i, String s) {}
    static void foo(Integer d) {}

    public static void main(String[] args) {
        I s = MyTest7::foo;
        s._(1);
    }
}