From 03287d5d66a50d01c0f0226c936a3aedfddd9711 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 16 Nov 2015 15:09:24 +0300 Subject: [PATCH] Diagnostics corrected for smart cast impossible --- .../kotlin/resolve/calls/smartcasts/DataFlowValue.kt | 6 +++--- .../resolve/calls/smartcasts/DataFlowValueFactory.java | 10 +++++----- idea/testData/checker/infos/SmartCasts.kt | 6 +++--- .../pureKotlin/valAddCustomAccessor/build.log | 2 +- .../pureKotlin/valRemoveCustomAccessor/build.log | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt index 5a31e30d703..e59dbe7e0dd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt @@ -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"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java index d068166541f..4a406f1c27f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java @@ -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 = diff --git a/idea/testData/checker/infos/SmartCasts.kt b/idea/testData/checker/infos/SmartCasts.kt index 224a5b2b2a2..6574dd64507 100644 --- a/idea/testData/checker/infos/SmartCasts.kt +++ b/idea/testData/checker/infos/SmartCasts.kt @@ -228,13 +228,13 @@ class Mutable(var x: Stri fun foo(): String { if (x is String) { - return x + return x } if (x != null) { - return x + return x } if (xx is String) { - return xx + return xx } return "" } diff --git a/jps-plugin/testData/incremental/pureKotlin/valAddCustomAccessor/build.log b/jps-plugin/testData/incremental/pureKotlin/valAddCustomAccessor/build.log index 0390b000838..71e16b9f6bb 100644 --- a/jps-plugin/testData/incremental/pureKotlin/valAddCustomAccessor/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/valAddCustomAccessor/build.log @@ -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 \ No newline at end of file +Smart cast to 'kotlin.Int' is impossible, because 'a.x' is a property that has open or custom getter \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/valRemoveCustomAccessor/build.log b/jps-plugin/testData/incremental/pureKotlin/valRemoveCustomAccessor/build.log index d998319baf2..2a97dbd6a90 100644 --- a/jps-plugin/testData/incremental/pureKotlin/valRemoveCustomAccessor/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/valRemoveCustomAccessor/build.log @@ -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: