Diagnostics corrected for smart cast impossible

This commit is contained in:
Mikhail Glukhikh
2015-11-16 15:09:24 +03:00
parent b4fe62e53e
commit 03287d5d66
5 changed files with 13 additions and 13 deletions

View File

@@ -33,10 +33,10 @@ class DataFlowValue(val id: Any?, val type: KotlinType, val kind: DataFlowValue.
STABLE_VALUE("stable"),
// Member value with open / custom getter
// 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
// 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
// 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"),
@@ -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"),
// Member variable regardless of its visibility
// 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
// Smart casts are not safe
OTHER("other", "complex expression");

View File

@@ -377,13 +377,13 @@ public class DataFlowValueFactory {
}
private static Kind propertyKind(@NotNull PropertyDescriptor propertyDescriptor, @Nullable ModuleDescriptor usageModule) {
if (propertyDescriptor.isVar()) return MEMBER_VARIABLE;
if (!isFinal(propertyDescriptor)) return MEMBER_VALUE_WITH_GETTER;
if (!hasDefaultGetter(propertyDescriptor)) return MEMBER_VALUE_WITH_GETTER;
if (propertyDescriptor.isVar()) return MUTABLE_PROPERTY;
if (!isFinal(propertyDescriptor)) return PROPERTY_WITH_GETTER;
if (!hasDefaultGetter(propertyDescriptor)) return PROPERTY_WITH_GETTER;
if (!invisibleFromOtherModules(propertyDescriptor)) {
ModuleDescriptor declarationModule = DescriptorUtils.getContainingModule(propertyDescriptor);
if (usageModule == null || !usageModule.equals(declarationModule)) {
return ALIEN_PUBLIC_VALUE;
return ALIEN_PUBLIC_PROPERTY;
}
}
return STABLE_VALUE;
@@ -400,7 +400,7 @@ public class DataFlowValueFactory {
}
if (!(variableDescriptor instanceof LocalVariableDescriptor) && !(variableDescriptor instanceof ParameterDescriptor)) return OTHER;
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
PreliminaryDeclarationVisitor preliminaryVisitor =

View File

@@ -228,13 +228,13 @@ class Mutable(var <info descr="This property has a backing field">x</info>: Stri
fun foo(): 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) {
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) {
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 ""
}

View File

@@ -12,4 +12,4 @@ Compiling files:
src/usage.kt
End of files
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

View File

@@ -6,7 +6,7 @@ Compiling files:
src/usage.kt
End of files
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: