IDEA-209947 Better type constraint explanation

GitOrigin-RevId: bc97ff49908ffee155459fb81dc5e46e4fb12c59
This commit is contained in:
Tagir Valeev
2019-04-28 16:46:26 +03:00
committed by intellij-monorepo-bot
parent 05188a3b0b
commit efcbb20422
9 changed files with 124 additions and 10 deletions
@@ -0,0 +1,17 @@
/*
Value is always false (s instanceof String)
An object is known to be Number which is definitely incompatible with String (s)
Type of 's' is known from line #10 (s instanceof Number)
*/
import java.util.List;
class Test {
void test(Object s) {
if (s instanceof Number) {
if (s instanceof Integer) {
if (<selection>s instanceof String</selection>){
}
}
}
}
}
@@ -0,0 +1,21 @@
/*
Value is always true (s instanceof RandomAccess)
An object is already known to be ArrayList which is a subtype of RandomAccess (s)
Type of 's' is known from line #12 (s instanceof ArrayList)
*/
import java.util.*;
class Test {
void test(Object s) {
if (s instanceof Map) {
if (s instanceof List) {
if (s instanceof ArrayList) {
if (s instanceof CharSequence) {
if (<selection>s instanceof RandomAccess</selection>){
}
}
}
}
}
}
}
@@ -1,6 +1,6 @@
/*
Value is always false (s instanceof Integer)
Type of 's' is exactly String (s)
An object type is exactly String which is not a subtype of Integer (s)
Type of 's' is known from line #10 (s instanceof String)
*/
import java.util.List;
@@ -0,0 +1,16 @@
/*
Value is always true (s instanceof String)
An object is already known to be String (s)
Type of 's' is known from line #10 ((String)s)
*/
import java.util.List;
class Test {
void test(Object s) {
System.out.println(((String)s).trim());
if (<selection>s instanceof String</selection>) {
}
}
}
@@ -1,6 +1,6 @@
/*
Value is always true (s instanceof CharSequence)
Type of 's' is exactly String (s)
An object type is exactly String which is a subtype of CharSequence (s)
Type of 's' is known from line #10 (s instanceof String)
*/
import java.util.List;
@@ -0,0 +1,17 @@
/*
Value is always false (s instanceof String)
An object is known to be not CharSequence which is a supertype of String (s)
Type of 's' is known from line #10 (s instanceof CharSequence)
*/
import java.util.List;
class Test {
void test(Object s) {
if (!(s instanceof CharSequence)) {
if (s instanceof Integer) {
if (<selection>s instanceof String</selection>){
}
}
}
}
}