Combined identifier info for things like '(x + y).z' is no longer treated as 'z' identifier info + a pair of tests + code fix #KT-9126 Fixed
This commit is contained in:
+5
-6
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
||||
@@ -188,16 +187,16 @@ public class DataFlowValueFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo createPackageInfo(Object id) {
|
||||
private static IdentifierInfo createPackageOrClassInfo(Object id) {
|
||||
return new IdentifierInfo(id, true, false, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo combineInfo(@Nullable IdentifierInfo receiverInfo, @NotNull IdentifierInfo selectorInfo) {
|
||||
if (selectorInfo.id == null) {
|
||||
if (selectorInfo.id == null || receiverInfo == NO_IDENTIFIER_INFO) {
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
if (receiverInfo == null || receiverInfo == NO_IDENTIFIER_INFO || receiverInfo.isPackage) {
|
||||
if (receiverInfo == null || receiverInfo.isPackage) {
|
||||
return selectorInfo;
|
||||
}
|
||||
return createInfo(Pair.create(receiverInfo.id, selectorInfo.id),
|
||||
@@ -281,8 +280,8 @@ public class DataFlowValueFactory {
|
||||
isStableVariable(variableDescriptor, usageModuleDescriptor),
|
||||
isUncapturedLocalVariable(variableDescriptor, bindingContext)));
|
||||
}
|
||||
if (declarationDescriptor instanceof PackageViewDescriptor) {
|
||||
return createPackageInfo(declarationDescriptor);
|
||||
if (declarationDescriptor instanceof PackageViewDescriptor || declarationDescriptor instanceof ClassDescriptor) {
|
||||
return createPackageOrClassInfo(declarationDescriptor);
|
||||
}
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNNECESSARY_NOT_NULL_ASSERTION
|
||||
// See KT-9126: Variable change does not affect data flow info for its fields
|
||||
|
||||
class My(val x: Int?)
|
||||
|
||||
fun foo() {
|
||||
var y: My? = My(42)
|
||||
if (y!!.x != null) {
|
||||
y = My(null)
|
||||
y!!.x<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
|
||||
public final class My {
|
||||
public constructor My(/*0*/ x: kotlin.Int?)
|
||||
public final val x: kotlin.Int?
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNNECESSARY_NOT_NULL_ASSERTION
|
||||
// Advancement of KT-9126
|
||||
|
||||
class My(val x: Int?) {
|
||||
fun plus(y: My) = if (this.x != null) this else y
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
var y: My? = My(42)
|
||||
if (y!!.x != null) {
|
||||
y = My(null)
|
||||
(<!DEBUG_INFO_SMARTCAST!>y<!> + My(0)).x<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
|
||||
public final class My {
|
||||
public constructor My(/*0*/ x: kotlin.Int?)
|
||||
public final val x: kotlin.Int?
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun plus(/*0*/ y: My): My
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -13197,6 +13197,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fieldExclExcl.kt")
|
||||
public void testFieldExclExcl() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fieldPlus.kt")
|
||||
public void testFieldPlus() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/fieldPlus.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt1461.kt")
|
||||
public void testKt1461() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");
|
||||
|
||||
@@ -73,7 +73,7 @@ public class JavaToKotlinAction : AnAction() {
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
{
|
||||
runReadAction {
|
||||
externalCodeUpdate = converterResult!!.externalCodeProcessing.prepareWriteOperation(ProgressManager.getInstance().getProgressIndicator())
|
||||
externalCodeUpdate = converterResult!!.externalCodeProcessing!!.prepareWriteOperation(ProgressManager.getInstance().getProgressIndicator())
|
||||
}
|
||||
},
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user