Skip to content

Commit 62b1910

Browse files
committed
isLocalVariable used together with isStableIdentifier for smart casts (both false positives now fail, but all three KT-3175 pass instead)
1 parent 8d9f887 commit 62b1910

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private static JetType updateResultTypeForSmartCasts(
446446
if (deparenthesizedArgument == null || type == null) return type;
447447

448448
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(deparenthesizedArgument, type, context);
449-
if (!dataFlowValue.isStableIdentifier()) return type;
449+
if (!dataFlowValue.isStableIdentifier() && !dataFlowValue.isLocalVariable()) return type;
450450

451451
Set<JetType> possibleTypes = context.dataFlowInfo.getPossibleTypes(dataFlowValue);
452452
if (possibleTypes.isEmpty()) return type;

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ public boolean isJumpPossible() {
9898
@Override
9999
@NotNull
100100
public Nullability getNullability(@NotNull DataFlowValue key) {
101-
if (!key.isStableIdentifier()) return key.getImmanentNullability();
101+
if (!key.isStableIdentifier() && !key.isLocalVariable()) return key.getImmanentNullability();
102102
Nullability nullability = nullabilityInfo.get(key);
103103
return nullability != null ? nullability :
104104
parent != null ? parent.getNullability(key) :
105105
key.getImmanentNullability();
106106
}
107107

108108
private boolean putNullability(@NotNull Map<DataFlowValue, Nullability> map, @NotNull DataFlowValue value, @NotNull Nullability nullability) {
109-
if (!value.isStableIdentifier()) return false;
109+
if (!value.isStableIdentifier() && !value.isLocalVariable()) return false;
110110
map.put(value, nullability);
111111
return nullability != getNullability(value);
112112
}

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public static boolean recordSmartCastIfNecessary(
179179
JetExpression expression = ((ExpressionReceiver) receiver).getExpression();
180180
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver, context);
181181

182-
recordCastOrError(expression, smartCastSubType, context.trace, dataFlowValue.isStableIdentifier(), true);
182+
recordCastOrError(expression,
183+
smartCastSubType,
184+
context.trace,
185+
dataFlowValue.isStableIdentifier() || dataFlowValue.isLocalVariable(),
186+
true);
183187
return true;
184188
}
185189

compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DataFlowUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ public static JetType checkType(
199199

200200
for (JetType possibleType : c.dataFlowInfo.getPossibleTypes(dataFlowValue)) {
201201
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, c.expectedType)) {
202-
SmartCastUtils.recordCastOrError(expression, possibleType, c.trace, dataFlowValue.isStableIdentifier(), false);
202+
SmartCastUtils.recordCastOrError(expression,
203+
possibleType,
204+
c.trace,
205+
dataFlowValue.isStableIdentifier() || dataFlowValue.isLocalVariable(),
206+
false);
203207
return possibleType;
204208
}
205209
}

idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/DataFlowInfoUtilForCompletion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
2424

2525
fun renderDataFlowValue(value: DataFlowValue): String? {
2626
// If it is not a stable identifier, there's no point in rendering it
27-
if (!value.isStableIdentifier()) return null
27+
if (!value.isStableIdentifier() && !value.isLocalVariable()) return null
2828

2929
fun renderId(id: Any?): String? {
3030
return when (id) {

0 commit comments

Comments
 (0)