mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 23:39:39 +07:00
java highlighting: provide better incompatible types message on failed inference
GitOrigin-RevId: 5f97ec808f753d9ca40c417704ec93a802512745
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6a7856d5c6
commit
afa0706bfc
@@ -7,10 +7,8 @@ public class Sample {
|
||||
<B> B bar(G<B> gb) {return null;}
|
||||
|
||||
void f(G1 g1) {
|
||||
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>
|
||||
G<String> l11 = <error descr="Incompatible types. Found: 'java.lang.Object', required: 'Sample.G<java.lang.String>'">bar(g1);</error>
|
||||
String l1 = <error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">bar(g1);</error>
|
||||
Object o = bar(g1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,14 @@ class Test {
|
||||
{
|
||||
Holder h = null;
|
||||
Result<String> r1 = new Result<error descr="Cannot infer arguments"><></error>(h);
|
||||
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>
|
||||
Result<String> r2 = <error descr="Incompatible types. Found: 'Result<Holder>', required: 'Result<java.lang.String>'">Result.create(h);</error>
|
||||
|
||||
Holder dataHolder = null;
|
||||
Result<String> r3 = new Result<error descr="Cannot infer arguments"><></error>(new Holder<>(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> r4 = <error descr="Incompatible types. Found: 'Result<Holder>', required: 'Result<java.lang.String>'">Result.create(new Holder<>(dataHolder));</error>
|
||||
|
||||
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(Holder.create(dataHolder));
|
||||
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>
|
||||
Result<String> r6 = <error descr="Incompatible types. Found: 'Result<Holder>', required: 'Result<java.lang.String>'">Result.create(Holder.create(dataHolder));</error>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,10 @@ import java.util.Map;
|
||||
class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
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>
|
||||
Map<Object, Object> b = <error descr="Incompatible types. Found: 'T', required: 'java.util.Map<java.lang.Object,java.lang.Object>'">newMapTrie();</error>
|
||||
Map<Object, Map<Object, Object>> c = <error descr="Incompatible types. Found: 'T', required: 'java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.lang.Object>>'">newMapTrie();</error>
|
||||
Map<Object, Map<Object, Map<Object, Object>>> d = <error descr="Incompatible types. Found: 'T', required: 'java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.lang.Object>>>'">newMapTrie();</error>
|
||||
Map<Object, Map<Object, Map<Object, Map<Object, Object>>>> e = <error descr="Incompatible types. Found: 'T', required: 'java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,java.lang.Object>>>>'">newMapTrie();</error>
|
||||
}
|
||||
|
||||
public static <T extends Map<Byte, T>> T newMapTrie() {
|
||||
|
||||
@@ -6,8 +6,7 @@ class Test {
|
||||
Factory factory = new Factory();
|
||||
final Class<? extends ClassB> bClass = null;
|
||||
ClassB b = factory.create(bClass);
|
||||
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">factory.create(bClass);</error>
|
||||
String str = <error descr="Incompatible types. Found: 'capture<? extends Test.ClassB>', required: 'java.lang.String'">factory.create(bClass);</error>
|
||||
}
|
||||
|
||||
public static class Factory {
|
||||
|
||||
@@ -6,9 +6,7 @@ class Test {
|
||||
}
|
||||
|
||||
void m(List l){
|
||||
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>
|
||||
boolean foo = <error descr="Incompatible types. Found: 'java.lang.Object', required: 'boolean'">foo(l);</error>
|
||||
String s = <error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">foo(l);</error>
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,7 @@ class Test1 {
|
||||
if (s.equals("1")) {
|
||||
return Option.option(1);
|
||||
} else {
|
||||
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>
|
||||
return <error descr="Incompatible types. Found: 'Test1.Option<java.lang.String>', required: 'Test1.Option<java.lang.Integer>'">Option.option("2");</error>
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ class TypeArgsConsistency {
|
||||
I<Integer> i1 = (i, j) -> i + j;
|
||||
foo((i, j) -> i + j);
|
||||
I<Integer> i2 = bar((i, j) -> i + j);
|
||||
I<Integer> i3 = bar(<error descr="no instance(s) of type variable(s) exist so that String conforms to Integer
|
||||
inference variable X has incompatible bounds:
|
||||
equality constraints: Integer
|
||||
lower bounds: String">(i, j) -> "" + i + j</error>);
|
||||
I<Integer> i3 = bar(<error descr="Incompatible types. Found: 'TypeArgsConsistency.I<java.lang.Object>', required: 'TypeArgsConsistency.I<java.lang.Integer>'">(i, j) -> "" + i + j</error>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +43,7 @@ class TypeArgsConsistency2 {
|
||||
I<Integer> i1 = bar(x -> x);
|
||||
I1<Integer> i2 = bar1(x -> 1);
|
||||
I2<String> aI2 = bar2(x -> "");
|
||||
I2<Integer> aI28 = bar2( <error descr="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">x-> ""</error>);
|
||||
I2<Integer> aI28 = bar2( <error descr="Incompatible types. Found: 'TypeArgsConsistency2.I2<java.lang.Object>', required: 'TypeArgsConsistency2.I2<java.lang.Integer>'">x-> ""</error>);
|
||||
I2<Integer> i3 = bar2(x -> x);
|
||||
I2<Integer> i4 = bar2(x -> foooI());
|
||||
System.out.println(i4.foo(2));
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
{
|
||||
final Map<Comparable, List<Collection<?>>> families = sortingMerge(<error descr="Incompatible equality constraint: Integer and Comparable">(s) -> 0</error>);
|
||||
final Map<Comparable, List<Collection<?>>> families = sortingMerge(<error descr="Incompatible types. Found: 'java.util.Map<C,java.util.List<java.lang.Object>>', required: 'java.util.Map<java.lang.Comparable,java.util.List<java.util.Collection<?>>>'">(s) -> 0</error>);
|
||||
}
|
||||
|
||||
private <C extends Comparable<C>, T> Map<C, List<T>> sortingMerge(Function<T, C> keyFunction) {
|
||||
|
||||
@@ -22,11 +22,7 @@ abstract class FooBar<M> {
|
||||
}
|
||||
class Test {
|
||||
<T> List<List<Object>> foo(List<T> objects, Function<T, ?>... functions) {
|
||||
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()
|
||||
return <error descr="Incompatible types. Found: 'java.util.List<java.util.List<capture<?>>>', required: 'java.util.List<java.util.List<java.lang.Object>>'">objects.stream()
|
||||
.map(object -> Arrays.stream(functions)
|
||||
.map(fn -> fn.apply(object))
|
||||
.collect(toList()))
|
||||
|
||||
@@ -9,8 +9,7 @@ class Test {
|
||||
|
||||
<R> SuperFoo<R> foo(I<R> ax) { return null; }
|
||||
|
||||
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">() -> new Foo<>()</error>);
|
||||
SuperFoo<String> ls = foo(<error descr="Incompatible types. Found: 'Test.SuperFoo<java.lang.Number>', required: 'Test.SuperFoo<java.lang.String>'">() -> new Foo<>()</error>);
|
||||
SuperFoo<Integer> li = foo(() -> new Foo<>());
|
||||
SuperFoo<?> lw = foo(() -> new Foo<>());
|
||||
}
|
||||
@@ -9,8 +9,7 @@ class A {
|
||||
<error descr="Missing return statement">}</error>);
|
||||
|
||||
|
||||
Map<Integer, Integer> map = Stream.iterate(5, <error descr="Incompatible types. Required Map<Integer, Integer> but 'iterate' was inferred to Stream<T>:
|
||||
no instance(s) of type variable(s) T exist so that Stream<T> conforms to Map<Integer, Integer>">t -> t + 5</error>);
|
||||
Map<Integer, Integer> map = Stream.iterate(5, <error descr="Incompatible types. Found: 'java.util.stream.Stream<java.lang.Integer>', required: 'java.util.Map<java.lang.Integer,java.lang.Integer>'">t -> t + 5</error>);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ abstract class NoFormalParamTypeInferenceNeeded {
|
||||
{
|
||||
map(a -> zip(text -> text));
|
||||
zip(a -> zip(text -> text));
|
||||
Integer zip = zip(<error descr="no instance(s) of type variable(s) exist so that Object conforms to Integer">a -> zip(text -> text)</error>);
|
||||
Integer zip = zip(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.Integer'">a -> zip(text -> text)</error>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
class MyTest {
|
||||
static Map<String, Meeting> <error descr="Invalid return type">getMeetingsById</error>(List<Meeting> meetings){
|
||||
return <error descr="Incompatible types. Required Map<String, Meeting> but 'collect' was inferred to R:
|
||||
no instance(s) of type variable(s) A, A, K, R, T exist so that List<T> conforms to Meeting">meetings.stream()
|
||||
return <error descr="Incompatible types. Found: 'java.util.Map<java.lang.String,java.util.List<Meeting>>', required: 'java.util.Map<java.lang.String,Meeting>'">meetings.stream()
|
||||
.collect(Collectors.groupingBy(Meeting::getId));</error>
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +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[]">x -> x</error>));
|
||||
valueOf(processFirst(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'char[]'">x -> x</error>));
|
||||
}
|
||||
|
||||
public static <V> V processFirst(Function<Integer,V> f){
|
||||
|
||||
@@ -9,7 +9,6 @@ class MyTest {
|
||||
}
|
||||
|
||||
{
|
||||
new MyTest("", <error descr="Incompatible types. Required int but 'emptyList' was inferred to List<T>:
|
||||
no instance(s) of type variable(s) T exist so that List<T> conforms to Integer">Collections.emptyList()</error>);
|
||||
new MyTest("", <error descr="Incompatible types. Found: 'java.util.List<java.lang.Object>', required: 'int'">Collections.emptyList()</error>);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
||||
class Test {
|
||||
|
||||
void foo() {
|
||||
log(<error descr="no instance(s) of type variable(s) exist so that TreeSet<String> conforms to String[]">get(TreeSet<String>::new)</error>);
|
||||
log(<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String[]'">get(TreeSet<String>::new)</error>);
|
||||
}
|
||||
|
||||
private void log(String params[]) {
|
||||
|
||||
Reference in New Issue
Block a user