java highlighting: provide better incompatible types message on failed inference

GitOrigin-RevId: 5f97ec808f753d9ca40c417704ec93a802512745
This commit is contained in:
Anna Kozlova
2019-07-08 10:43:57 +02:00
committed by intellij-monorepo-bot
parent 6a7856d5c6
commit afa0706bfc
28 changed files with 87 additions and 101 deletions

View File

@@ -17,15 +17,13 @@ class MyTest {
void m(int i) {
String s = foo(switch (i) {default -> "str";});
String s1 = <error descr="Incompatible types. Required String but 'foo' was inferred to T:
no instance(s) of type variable(s) exist so that Object conforms to String">foo(switch (i) {case 1 -> new Object(); default -> "str";});</error>
String s1 = <error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">foo(switch (i) {case 1 -> new Object(); default -> "str";});</error>
String s2 = foo(() -> switch (i) {
default -> "str";
});
String s3 = foo(() -> switch (i) {default -> bar();});
String s4 = foo(() -> switch (i) {default -> { yield bar();}});
String s5 = foo(<error descr="Incompatible types. Required String but 'foo' was inferred to T:
no instance(s) of type variable(s) exist so that Integer conforms to String">() -> switch (i) {default -> { yield 1;}}</error>);
String s5 = foo(<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.String'">() -> switch (i) {default -> { yield 1;}}</error>);
String s6 = switch (i) {
case 1 -> <error descr="Bad type in switch expression: int cannot be converted to java.lang.String">2</error>;
default -> {