inference errors: make applicability error thread safe so multiple threads can perform overload resolution of parent method calls independently, save presentable error when substitutor cached only

This commit is contained in:
Anna Kozlova
2017-05-08 12:07:00 +03:00
parent fa07225451
commit 77f4894aae
36 changed files with 145 additions and 136 deletions

View File

@@ -7,8 +7,10 @@ public class Sample {
<B> B bar(G<B> gb) {return null;}
void f(G1 g1) {
G<String> l11 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
String l1 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
G<String> l11 = <error descr="Incompatible types. Required G<String> but 'bar' was inferred to B:
Incompatible types: Object is not convertible to G<String>">bar(g1);</error>
String l1 = <error descr="Incompatible types. Required String but 'bar' was inferred to B:
Incompatible types: Object is not convertible to String">bar(g1);</error>
Object o = bar(g1);
}
}

View File

@@ -2,14 +2,27 @@ class Test {
{
Holder h = null;
Result<String> r1 = new Result<error descr="Cannot infer arguments"><></error>(h);
Result<String> r2 = Result.create<error descr="'create(K)' in 'Result' cannot be applied to '(Holder)'">(h)</error>;
Result<String> r2 = <error descr="Incompatible types. Required Result<String> but 'create' was inferred to Result<K>:
no instance(s) of type variable(s) exist so that Holder conforms to String
inference variable K has incompatible bounds:
equality constraints: String
lower bounds: Holder">Result.create(h);</error>
Holder dataHolder = null;
Result<String> r3 = new Result<error descr="Cannot infer arguments"><></error>(new Holder<error descr="Cannot infer arguments"><></error>(dataHolder));
Result<String> r4 = Result.create(new Holder<error descr="Cannot infer arguments"><></error>(dataHolder));
Result<String> r4 = <error descr="Incompatible types. Required Result<String> but 'create' was inferred to Result<K>:
no instance(s) of type variable(s) exist so that Holder conforms to String
inference variable K has incompatible bounds:
equality constraints: String
lower bounds: Holder">Result.create(new Holder<>(dataHolder));</error>
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(Holder.create<error descr="'create(Holder<M>)' in 'Holder' cannot be applied to '(Holder)'">(dataHolder)</error>);
Result<String> r6 = Result.create(Holder.create<error descr="'create(Holder<M>)' in 'Holder' cannot be applied to '(Holder)'">(dataHolder)</error>);
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(<error descr="Incompatible types. Required D but 'create' was inferred to Holder<M>:
Incompatible types: Holder is not convertible to D">Holder.create(dataHolder)</error>);
Result<String> r6 = <error descr="Incompatible types. Required Result<String> but 'create' was inferred to Result<K>:
no instance(s) of type variable(s) exist so that Holder conforms to String
inference variable K has incompatible bounds:
equality constraints: String
lower bounds: Holder">Result.create(Holder.create(dataHolder));</error>
}
}

View File

@@ -7,6 +7,6 @@ class Test2 {
}
{
foo (bar<error descr="'bar(java.lang.Class<T>)' in 'Test2' cannot be applied to '(java.lang.Class<java.lang.String>)'">(String.class)</error>, "");
foo (bar(String.class), <error descr="'foo(java.lang.String, java.lang.Integer)' in 'Test2' cannot be applied to '(T, java.lang.String)'">""</error>);
}
}

View File

@@ -20,10 +20,10 @@ class TestIDEA128101 {
public static void test() {
construct(String.class, createPath(integerAttribute), createPath(stringAttribute));
construct1(String.class, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.Integer>)'">(integerAttribute)</error>, createPath(stringAttribute));
construct1<error descr="'construct1(java.lang.Class<T>, TestIDEA128101.Path<K>...)' in 'TestIDEA128101' cannot be applied to '(java.lang.Class<java.lang.String>, TestIDEA128101.Path<Y>, TestIDEA128101.Path<java.lang.String>)'">(String.class, createPath(integerAttribute), createPath(stringAttribute))</error>;
construct2(String.class, createPath(integerAttribute), createPath(stringAttribute));
construct3(String.class, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.Integer>)'">(integerAttribute)</error>, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.String>)'">(stringAttribute)</error>);
construct4(String.class, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.Integer>)'">(integerAttribute)</error>, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.String>)'">(stringAttribute)</error>);
construct3<error descr="'construct3(java.lang.Class<java.lang.String>, TestIDEA128101.Path<? super K>...)' in 'TestIDEA128101' cannot be applied to '(java.lang.Class<java.lang.String>, TestIDEA128101.Path<Y>, TestIDEA128101.Path<Y>)'">(String.class, createPath(integerAttribute), createPath(stringAttribute))</error>;
construct4<error descr="'construct4(java.lang.Class<java.lang.String>, TestIDEA128101.Path<? super K>, TestIDEA128101.Path<? super K>)' in 'TestIDEA128101' cannot be applied to '(java.lang.Class<java.lang.String>, TestIDEA128101.Path<Y>, TestIDEA128101.Path<Y>)'">(String.class, createPath(integerAttribute), createPath(stringAttribute))</error>;
}
}

View File

@@ -3,10 +3,14 @@ import java.util.Map;
class Test {
public static void main(String[] args) {
Map<Object, Object> b = newMapTrie<error descr="'newMapTrie()' in 'Test' cannot be applied to '()'">()</error>;
Map<Object, Map<Object, Object>> c = newMapTrie<error descr="'newMapTrie()' in 'Test' cannot be applied to '()'">()</error>;
Map<Object, Map<Object, Map<Object, Object>>> d = newMapTrie<error descr="'newMapTrie()' in 'Test' cannot be applied to '()'">()</error>;
Map<Object, Map<Object, Map<Object, Map<Object, Object>>>> e = newMapTrie<error descr="'newMapTrie()' in 'Test' cannot be applied to '()'">()</error>;
Map<Object, Object> b = <error descr="Incompatible types. Required Map<Object, Object> but 'newMapTrie' was inferred to T:
Incompatible equality constraint: Byte and Object">newMapTrie();</error>
Map<Object, Map<Object, Object>> c = <error descr="Incompatible types. Required Map<Object, Map<Object, Object>> but 'newMapTrie' was inferred to T:
Incompatible equality constraint: Byte and Object">newMapTrie();</error>
Map<Object, Map<Object, Map<Object, Object>>> d = <error descr="Incompatible types. Required Map<Object, Map<Object, Map<Object, Object>>> but 'newMapTrie' was inferred to T:
Incompatible equality constraint: Byte and Object">newMapTrie();</error>
Map<Object, Map<Object, Map<Object, Map<Object, Object>>>> e = <error descr="Incompatible types. Required Map<Object, Map<Object, Map<Object, Map<Object, Object>>>> but 'newMapTrie' was inferred to T:
Incompatible equality constraint: Byte and Object">newMapTrie();</error>
}
public static <T extends Map<Byte, T>> T newMapTrie() {

View File

@@ -6,7 +6,11 @@ class Test {
Factory factory = new Factory();
final Class<? extends ClassB> bClass = null;
ClassB b = factory.create(bClass);
String str = factory.create<error descr="'create(java.lang.Class<T>)' in 'Test.Factory' cannot be applied to '(java.lang.Class<capture<? extends Test.ClassB>>)'">(bClass)</error>;
String str = <error descr="Incompatible types. Required String but 'create' was inferred to T:
no instance(s) of type variable(s) exist so that capture of ? extends ClassB conforms to String
inference variable T has incompatible bounds:
equality constraints: capture of ? extends ClassB
upper bounds: ClassA<I>, Object, String">factory.create(bClass);</error>
}
public static class Factory {

View File

@@ -29,7 +29,8 @@ public class ConcurrentCollectors {
static <T, K, D, M1 extends Map<K, D>> C<T, M1> groupingBy(F<M1> f,
C<T, D> c,
BiConsumer<M1, T> consumer) {
return new CImpl<error descr="Cannot infer arguments"><></error>(f, consumer, arg<error descr="'arg(ConcurrentCollectors.BiOp<V>)' in 'ConcurrentCollectors.Test3' cannot be applied to '(ConcurrentCollectors.BiOp<D>)'">(c.getOp())</error>);
return new CImpl<error descr="Cannot infer arguments"><></error>(f, consumer, <error descr="Incompatible types. Required BiOp<R> but 'arg' was inferred to BiOp<M2>:
no instance(s) of type variable(s) K, V exist so that R conforms to ConcurrentMap<K, V>">arg(c.getOp())</error>);
}
static <K, V, M2 extends ConcurrentMap<K, V>> BiOp<M2> arg(BiOp<V> op) {

View File

@@ -6,7 +6,9 @@ class Test {
}
void m(List l){
boolean foo = foo<error descr="'foo(java.util.List<T>)' in 'Test' cannot be applied to '(java.util.List)'">(l)</error>;
String s = foo<error descr="'foo(java.util.List<T>)' in 'Test' cannot be applied to '(java.util.List)'">(l)</error>;
boolean foo = <error descr="Incompatible types. Required boolean but 'foo' was inferred to T:
Incompatible types: Object is not convertible to boolean">foo(l);</error>
String s = <error descr="Incompatible types. Required String but 'foo' was inferred to T:
Incompatible types: Object is not convertible to String">foo(l);</error>
}
}

View File

@@ -37,7 +37,11 @@ class Test1 {
if (s.equals("1")) {
return Option.option(1);
} else {
return Option.option<error descr="'option(T)' in 'Test1.Option' cannot be applied to '(java.lang.String)'">("2")</error>;
return <error descr="Incompatible types. Required Option<Integer> but 'option' was inferred to Option<T>:
no instance(s) of type variable(s) exist so that String conforms to Integer
inference variable T has incompatible bounds:
equality constraints: Integer
lower bounds: String">Option.option("2");</error>
}
};
}

View File

@@ -24,7 +24,7 @@ class AlienTest {
static {
IInt i1 = MyTest::<error descr="Cannot resolve method 'abracadabra'">abracadabra</error>;
IInt i2 = MyTest::<error descr="Invalid method reference: int cannot be converted to String">foo</error>;
IInt i2 = MyTest::<error descr="Cannot resolve method 'foo'">foo</error>;
IInt i3 = MyTest::<error descr="Cannot resolve method 'bar'">bar</error>;
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IIntInt'">IIntInt i4 = MyTest::bar;</error>
IInt i5 = <error descr="Non-static method cannot be referenced from a static context">MyTest::baz</error>;

View File

@@ -47,7 +47,7 @@ class MyTest1 {
}
{
Bar1 b1 = MyTest2 :: <error descr="Invalid method reference: String cannot be converted to int">foo</error>;
Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
bar(MyTest1 :: foo);
}
}
@@ -73,7 +73,7 @@ class MyTest2 {
}*/
{
Bar1 b1 = MyTest2 :: <error descr="Invalid method reference: String cannot be converted to int">foo</error>;
Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
bar(MyTest2 :: foo);
}
}
@@ -99,8 +99,8 @@ class MyTest3 {
}
{
Bar1 b1 = MyTest2 :: <error descr="Invalid method reference: String cannot be converted to int">foo</error>;
bar(MyTest3 :: <error descr="Invalid method reference: int cannot be converted to String">foo</error>);
Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
bar(MyTest3 :: <error descr="Cannot resolve method 'foo'">foo</error>);
}
}

View File

@@ -2,7 +2,7 @@ class Test {
{
Runnable b = Test :: <error descr="Cannot resolve method 'length'">length</error>;
Comparable<String> c = Test :: length;
Comparable<Integer> c1 = Test :: <error descr="Invalid method reference: Integer cannot be converted to String">length</error>;
Comparable<Integer> c1 = Test :: <error descr="Cannot resolve method 'length'">length</error>;
}
public static Integer length(String s) {

View File

@@ -49,7 +49,7 @@ class MyTest {
static {
I1 i1 = MyTest::static_1;
I1 i2 = MyTest::<error descr="Cannot resolve method 'static_2'">static_2</error>;
I1 i3 = MyTest::<error descr="Invalid method reference: int cannot be converted to String">static_3</error>;
I1 i3 = MyTest::<error descr="Cannot resolve method 'static_3'">static_3</error>;
I1 i4 = MyTest::<error descr="Cannot resolve method 'static_4'">static_4</error>;
}
@@ -62,7 +62,7 @@ class MyTest {
I1 i1 = this::_1;
I1 i2 = this::<error descr="Cannot resolve method '_2'">_2</error>;
I1 i3 = this::<error descr="Invalid method reference: int cannot be converted to String">_3</error>;
I1 i3 = this::<error descr="Cannot resolve method '_3'">_3</error>;
I1 i4 = this::<error descr="Cannot resolve method '_4'">_4</error>;
I2 i21 = MyTest::<error descr="Cannot resolve method 'm1'">m1</error>;

View File

@@ -32,7 +32,7 @@ class Test1 {
}
{
bar(l -> baz<error descr="'baz(T)' in 'Test1' cannot be applied to '(java.lang.Object)'">(l)</error>);
bar(l -> <error descr="Unhandled exception: Test1.MyEx">baz(l)</error>);
bar(<error descr="Unhandled exception: Test1.MyEx">this::baz</error>);
}
}

View File

@@ -22,10 +22,14 @@ abstract class FooBar<M> {
}
class Test {
<T> List<List<Object>> foo(List<T> objects, Function<T, ?>... functions) {
return objects.stream()
return <error descr="Incompatible types. Required List<List<Object>> but 'collect' was inferred to R:
no instance(s) of type variable(s) exist so that List<capture of ?> conforms to List<Object>
inference variable T has incompatible bounds:
equality constraints: List<Object>
lower bounds: List<capture of ?>">objects.stream()
.map(object -> Arrays.stream(functions)
.map(fn -> fn.apply(object))
.collect(toList()))
.collect(toList<error descr="'toList()' in 'java.util.stream.Collectors' cannot be applied to '()'">()</error>);
.collect(toList());</error>
}
}

View File

@@ -9,7 +9,11 @@ class Test {
<R> SuperFoo<R> foo(I<R> ax) { return null; }
SuperFoo<String> ls = foo(() -> new Foo<error descr="Cannot infer arguments"><></error>());
SuperFoo<String> ls = foo(<error descr="Incompatible types. Required SuperFoo<String> but 'foo' was inferred to SuperFoo<R>:
no instance(s) of type variable(s) exist so that String conforms to Number
inference variable R has incompatible bounds:
equality constraints: String
upper bounds: Object, Number">() -> new Foo<>()</error>);
SuperFoo<Integer> li = foo(() -> new Foo<>());
SuperFoo<?> lw = foo(() -> new Foo<>());
}

View File

@@ -26,10 +26,7 @@ abstract class NoFormalParamTypeInferenceNeeded {
{
map(a -> zip(text -> text));
zip(a -> zip(text -> text));
Integer zip = zip(a -> zip(<error descr="no instance(s) of type variable(s) exist so that Object conforms to Integer
inference variable R has incompatible bounds:
lower bounds: Object
upper bounds: Object, Integer">text -> text</error>));
Integer zip = zip(a -> zip(text -> <error descr="Bad return type in lambda expression: Object cannot be converted to R">text</error>));
}
}

View File

@@ -5,7 +5,7 @@ class A {
public static void main(String[] args) {
B<? extends CharSequence> q = new B<>();
Func x = q::<error descr="Invalid method reference: CharSequence cannot be converted to capture of ? extends CharSequence">foo</error>;
Func x = q::<error descr="Cannot resolve method 'foo'">foo</error>;
x.invoke("");
}

View File

@@ -7,7 +7,7 @@ interface B<BT> {
class Test {
public static void test() {
method1(Test::<error descr="Invalid method reference: A<capture of ? super M> cannot be converted to A<? super String>">method2</error>);
method1(Test::<error descr="Cannot resolve method 'method2'">method2</error>);
}
static <M> void method1(B<A<? super M>> arg) { }

View File

@@ -4,7 +4,7 @@ import java.util.function.Predicate;
class MyTest {
{
BiConsumer<Predicate<? extends Runnable>, Predicate<? extends Runnable>> or = MyTest::<error descr="Invalid method reference: Predicate<capture of ? extends Runnable> cannot be converted to Predicate<E>">or</error>;
BiConsumer<Predicate<? extends Runnable>, Predicate<? extends Runnable>> or = MyTest::<error descr="Cannot resolve method 'or'">or</error>;
}
private static <E extends Runnable> void or(Predicate<E> left, Predicate<E> right) {}

View File

@@ -29,14 +29,14 @@ class Test {
static void meth4(I3 s) { }
static {
meth1(Foo::<error descr="Invalid constructor reference: String cannot be converted to Number">new</error>);
meth1(Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>);
meth2(Foo::new);
meth3(Foo::<error descr="Invalid constructor reference: Object cannot be converted to Number">new</error>);
meth3(Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>);
meth4<error descr="Ambiguous method call: both 'Test.meth4(I1)' and 'Test.meth4(I2)' match">(Foo::new)</error>;
meth1(Test::<error descr="Invalid method reference: String cannot be converted to X">foo</error>);
meth1(Test::<error descr="Cannot resolve method 'foo'">foo</error>);
meth2(Test::foo);
meth3(Test::<error descr="Invalid method reference: Object cannot be converted to X">foo</error>);
meth3(Test::<error descr="Cannot resolve method 'foo'">foo</error>);
meth4<error descr="Ambiguous method call: both 'Test.meth4(I1)' and 'Test.meth4(I2)' match">(Test::foo)</error>;
}
@@ -55,8 +55,8 @@ class Test {
}
void test() {
II1 i1 = this::<error descr="Invalid method reference: X cannot be converted to X">fooInstance</error>;
II1 i1 = this::<error descr="Cannot resolve method 'fooInstance'">fooInstance</error>;
II2 i2 = this::fooInstance;
II3 i3 = this::<error descr="Invalid method reference: X cannot be converted to X">fooInstance</error>;
II3 i3 = this::<error descr="Cannot resolve method 'fooInstance'">fooInstance</error>;
}
}

View File

@@ -17,7 +17,7 @@ abstract class Test {
{
I i = Test::<String>foo;
I i1 = Test::<Integer><error descr="Invalid method reference: String cannot be converted to Integer">foo</error>;
I i1 = Test::<Integer><error descr="Cannot resolve method 'foo'">foo</error>;
I i2 = Test::foo;
}

View File

@@ -4,7 +4,7 @@ class InlineRef {
<K> void foo(Consumer<K> f) {}
void bar(){
foo(Descriptor::<error descr="Invalid method reference: Object cannot be converted to Descriptor">getName</error>);
foo(Descriptor::<error descr="Cannot resolve method 'getName'">getName</error>);
}
}

View File

@@ -4,6 +4,6 @@ import java.util.Comparator;
class Main {
public void test() {
Collections.sort(new ArrayList<error descr="Cannot infer arguments"><></error>(), <error descr="Non-static method cannot be referenced from a static context">Comparator::reversed</error>);
Collections.sort(new ArrayList<>(), <error descr="Non-static method cannot be referenced from a static context">Comparator::reversed</error>);
}
}

View File

@@ -12,10 +12,7 @@ import java.util.function.Function;
class Test {
{
valueOf(processFirst(<error descr="no instance(s) of type variable(s) exist so that Integer conforms to char[]
inference variable V has incompatible bounds:
lower bounds: Integer
upper bounds: Object, char[]">x -> x</error>));
valueOf(processFirst(x -> <error descr="Bad return type in lambda expression: Integer cannot be converted to V">x</error>));
}
public static <V> V processFirst(Function<Integer,V> f){