Diagnostics corrected for smart cast impossible
This commit is contained in:
+3
-3
@@ -33,10 +33,10 @@ class DataFlowValue(val id: Any?, val type: KotlinType, val kind: DataFlowValue.
|
|||||||
STABLE_VALUE("stable"),
|
STABLE_VALUE("stable"),
|
||||||
// Member value with open / custom getter
|
// Member value with open / custom getter
|
||||||
// Smart casts are not safe
|
// Smart casts are not safe
|
||||||
MEMBER_VALUE_WITH_GETTER("custom getter", "member value that has open or custom getter"),
|
PROPERTY_WITH_GETTER("custom getter", "property that has open or custom getter"),
|
||||||
// Protected / public member value from another module
|
// Protected / public member value from another module
|
||||||
// Smart casts are not safe
|
// Smart casts are not safe
|
||||||
ALIEN_PUBLIC_VALUE("alien public", "public API member value declared in different module"),
|
ALIEN_PUBLIC_PROPERTY("alien public", "public API property declared in different module"),
|
||||||
// Local variable not yet captured by a changing closure
|
// Local variable not yet captured by a changing closure
|
||||||
// Smart casts are safe but possible changes in loops / closures ahead must be taken into account
|
// Smart casts are safe but possible changes in loops / closures ahead must be taken into account
|
||||||
PREDICTABLE_VARIABLE("predictable", "local variable that can be changed since the check in a loop"),
|
PREDICTABLE_VARIABLE("predictable", "local variable that can be changed since the check in a loop"),
|
||||||
@@ -45,7 +45,7 @@ class DataFlowValue(val id: Any?, val type: KotlinType, val kind: DataFlowValue.
|
|||||||
UNPREDICTABLE_VARIABLE("unpredictable", "local variable that is captured by a changing closure"),
|
UNPREDICTABLE_VARIABLE("unpredictable", "local variable that is captured by a changing closure"),
|
||||||
// Member variable regardless of its visibility
|
// Member variable regardless of its visibility
|
||||||
// Smart casts are not safe
|
// Smart casts are not safe
|
||||||
MEMBER_VARIABLE("member", "member variable that can be changed from another thread"),
|
MUTABLE_PROPERTY("member", "mutable property that could have been changed by this time"),
|
||||||
// Some complex expression
|
// Some complex expression
|
||||||
// Smart casts are not safe
|
// Smart casts are not safe
|
||||||
OTHER("other", "complex expression");
|
OTHER("other", "complex expression");
|
||||||
|
|||||||
+5
-5
@@ -377,13 +377,13 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Kind propertyKind(@NotNull PropertyDescriptor propertyDescriptor, @Nullable ModuleDescriptor usageModule) {
|
private static Kind propertyKind(@NotNull PropertyDescriptor propertyDescriptor, @Nullable ModuleDescriptor usageModule) {
|
||||||
if (propertyDescriptor.isVar()) return MEMBER_VARIABLE;
|
if (propertyDescriptor.isVar()) return MUTABLE_PROPERTY;
|
||||||
if (!isFinal(propertyDescriptor)) return MEMBER_VALUE_WITH_GETTER;
|
if (!isFinal(propertyDescriptor)) return PROPERTY_WITH_GETTER;
|
||||||
if (!hasDefaultGetter(propertyDescriptor)) return MEMBER_VALUE_WITH_GETTER;
|
if (!hasDefaultGetter(propertyDescriptor)) return PROPERTY_WITH_GETTER;
|
||||||
if (!invisibleFromOtherModules(propertyDescriptor)) {
|
if (!invisibleFromOtherModules(propertyDescriptor)) {
|
||||||
ModuleDescriptor declarationModule = DescriptorUtils.getContainingModule(propertyDescriptor);
|
ModuleDescriptor declarationModule = DescriptorUtils.getContainingModule(propertyDescriptor);
|
||||||
if (usageModule == null || !usageModule.equals(declarationModule)) {
|
if (usageModule == null || !usageModule.equals(declarationModule)) {
|
||||||
return ALIEN_PUBLIC_VALUE;
|
return ALIEN_PUBLIC_PROPERTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return STABLE_VALUE;
|
return STABLE_VALUE;
|
||||||
@@ -400,7 +400,7 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
if (!(variableDescriptor instanceof LocalVariableDescriptor) && !(variableDescriptor instanceof ParameterDescriptor)) return OTHER;
|
if (!(variableDescriptor instanceof LocalVariableDescriptor) && !(variableDescriptor instanceof ParameterDescriptor)) return OTHER;
|
||||||
if (!variableDescriptor.isVar()) return STABLE_VALUE;
|
if (!variableDescriptor.isVar()) return STABLE_VALUE;
|
||||||
if (variableDescriptor instanceof SyntheticFieldDescriptor) return MEMBER_VARIABLE;
|
if (variableDescriptor instanceof SyntheticFieldDescriptor) return MUTABLE_PROPERTY;
|
||||||
|
|
||||||
// Local variable classification: PREDICTABLE or UNPREDICTABLE
|
// Local variable classification: PREDICTABLE or UNPREDICTABLE
|
||||||
PreliminaryDeclarationVisitor preliminaryVisitor =
|
PreliminaryDeclarationVisitor preliminaryVisitor =
|
||||||
|
|||||||
+3
-3
@@ -228,13 +228,13 @@ class Mutable(var <info descr="This property has a backing field">x</info>: Stri
|
|||||||
|
|
||||||
fun foo(): String {
|
fun foo(): String {
|
||||||
if (x is String) {
|
if (x is String) {
|
||||||
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'x' is a member variable that can be changed from another thread">x</error>
|
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'x' is a mutable property that could have been changed by this time">x</error>
|
||||||
}
|
}
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'x' is a member variable that can be changed from another thread">x</error>
|
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'x' is a mutable property that could have been changed by this time">x</error>
|
||||||
}
|
}
|
||||||
if (xx is String) {
|
if (xx is String) {
|
||||||
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'xx' is a member value that has open or custom getter">xx</error>
|
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'xx' is a property that has open or custom getter">xx</error>
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ Compiling files:
|
|||||||
src/usage.kt
|
src/usage.kt
|
||||||
End of files
|
End of files
|
||||||
COMPILATION FAILED
|
COMPILATION FAILED
|
||||||
Smart cast to 'kotlin.Int' is impossible, because 'a.x' is a member value that has open or custom getter
|
Smart cast to 'kotlin.Int' is impossible, because 'a.x' is a property that has open or custom getter
|
||||||
+1
-1
@@ -6,7 +6,7 @@ Compiling files:
|
|||||||
src/usage.kt
|
src/usage.kt
|
||||||
End of files
|
End of files
|
||||||
COMPILATION FAILED
|
COMPILATION FAILED
|
||||||
Smart cast to 'kotlin.Int' is impossible, because 'a.x' is a member value that has open or custom getter
|
Smart cast to 'kotlin.Int' is impossible, because 'a.x' is a property that has open or custom getter
|
||||||
|
|
||||||
|
|
||||||
Cleaning output files:
|
Cleaning output files:
|
||||||
|
|||||||
Reference in New Issue
Block a user