KT-6527 Wrong diagnostics when compare dynamic to null
#KT-6527 Fixed
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.smartcasts;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ public class DataFlowValue {
|
|||||||
|
|
||||||
public static final DataFlowValue NULL = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableNothingType(), false, Nullability.NULL);
|
public static final DataFlowValue NULL = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableNothingType(), false, Nullability.NULL);
|
||||||
public static final DataFlowValue NULLABLE = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableAnyType(), false, Nullability.UNKNOWN);
|
public static final DataFlowValue NULLABLE = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableAnyType(), false, Nullability.UNKNOWN);
|
||||||
|
public static final DataFlowValue ERROR = new DataFlowValue(new Object(), ErrorUtils.createErrorType("Error type for data flow"), false, Nullability.IMPOSSIBLE);
|
||||||
|
|
||||||
private final boolean stableIdentifier;
|
private final boolean stableIdentifier;
|
||||||
private final JetType type;
|
private final JetType type;
|
||||||
|
|||||||
+2
-1
@@ -45,7 +45,8 @@ public class DataFlowValueFactory {
|
|||||||
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
||||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
||||||
}
|
}
|
||||||
if (TypeUtils.equalTypes(type, KotlinBuiltIns.getInstance().getNullableNothingType())) return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
if (type.isError()) return DataFlowValue.ERROR;
|
||||||
|
if (KotlinBuiltIns.getInstance().getNullableNothingType().equals(type)) return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
||||||
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext);
|
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext);
|
||||||
return new DataFlowValue(result == NO_IDENTIFIER_INFO ? expression : result.id, type, result.isStable, getImmanentNullability(type));
|
return new DataFlowValue(result == NO_IDENTIFIER_INFO ? expression : result.id, type, result.isStable, getImmanentNullability(type));
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
public final fun get(/*0*/ p0: dynamic): dynamic
|
||||||
|
public final fun get(/*0*/ p0: dynamic): dynamic
|
||||||
|
public final var foo: dynamic
|
||||||
|
public final fun <get-foo>(): dynamic
|
||||||
|
public final fun <set-foo>(/*0*/ <set-?>: dynamic): kotlin.Unit
|
||||||
|
public final var foo: dynamic
|
||||||
|
public final fun <get-foo>(): dynamic
|
||||||
|
public final fun <set-foo>(/*0*/ <set-?>: dynamic): kotlin.Unit
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
fun test(d: dynamic) {
|
||||||
|
d == null
|
||||||
|
d != null
|
||||||
|
d["foo"] == null
|
||||||
|
d["foo"] != null
|
||||||
|
d.foo == null
|
||||||
|
d.foo != null
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun test(/*0*/ d: dynamic): kotlin.Unit
|
||||||
@@ -7,8 +7,12 @@ fun test(d: dynamic) {
|
|||||||
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!>
|
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!>
|
||||||
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!> = 1
|
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!> = 1
|
||||||
|
|
||||||
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!>
|
run {
|
||||||
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!> = 1
|
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!>
|
||||||
|
}
|
||||||
|
run {
|
||||||
|
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVal<!> = 1
|
||||||
|
}
|
||||||
|
|
||||||
d.<!DEBUG_INFO_DYNAMIC!>onNullableAnyVal<!> = 1
|
d.<!DEBUG_INFO_DYNAMIC!>onNullableAnyVal<!> = 1
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,13 @@ fun test(d: dynamic) {
|
|||||||
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!>
|
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!>
|
||||||
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!> = 1
|
d?.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!> = 1
|
||||||
|
|
||||||
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!>
|
run {
|
||||||
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!> = 1
|
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!>
|
||||||
|
|
||||||
|
}
|
||||||
|
run {
|
||||||
|
d!!.<!DEBUG_INFO_DYNAMIC!>onAnyVar<!> = 1
|
||||||
|
}
|
||||||
|
|
||||||
d.<!DEBUG_INFO_DYNAMIC!>onNullableAnyVar<!> = 1
|
d.<!DEBUG_INFO_DYNAMIC!>onNullableAnyVar<!> = 1
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
fun test(d: dynamic) {
|
fun test(d: dynamic) {
|
||||||
d.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
d.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
||||||
d?.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
d?.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
||||||
d!!.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
run {
|
||||||
|
d!!.<!DEBUG_INFO_DYNAMIC!>onAny<!>()
|
||||||
|
}
|
||||||
|
|
||||||
d.<!DEBUG_INFO_DYNAMIC!>onAny<!>(1)
|
d.<!DEBUG_INFO_DYNAMIC!>onAny<!>(1)
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,19 @@ fun test(d: dynamic) {
|
|||||||
|
|
||||||
d.equals(1)
|
d.equals(1)
|
||||||
d?.equals(1)
|
d?.equals(1)
|
||||||
d!!.equals(1)
|
run {
|
||||||
|
d!!.equals(1)
|
||||||
|
}
|
||||||
|
|
||||||
d.hashCode()
|
d.hashCode()
|
||||||
d?.hashCode()
|
d?.hashCode()
|
||||||
d!!.hashCode()
|
run {
|
||||||
|
d!!.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
d.toString()
|
d.toString()
|
||||||
d?.toString()
|
d?.toString()
|
||||||
d!!.toString()
|
run {
|
||||||
|
d!!.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
@@ -67,6 +67,12 @@ public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnost
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("comparisonToNull.kt")
|
||||||
|
public void testComparisonToNull() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/comparisonToNull.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("conditions.kt")
|
@TestMetadata("conditions.kt")
|
||||||
public void testConditions() throws Exception {
|
public void testConditions() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user