[LC] Fixed light classes nullability for Kotlin 1.5

Fixed #KT-44472
This commit is contained in:
Igor Yakovlev
2021-04-15 19:14:39 +02:00
parent 63160293fb
commit e4870740e1
18 changed files with 54 additions and 64 deletions

View File

@@ -241,7 +241,7 @@ fun fastCheckIsNullabilityApplied(lightElement: KtLightElement<*, PsiModifierLis
// backing fields for lateinit props are skipped
if (lightElement is KtLightField && annotatedElement is KtProperty && annotatedElement.hasModifier(KtTokens.LATEINIT_KEYWORD)) return false
if (lightElement is KtLightField && (annotatedElement as? KtModifierListOwner)?.isPrivate() == true) {
if (lightElement is KtLightMethod && (annotatedElement as? KtModifierListOwner)?.isPrivate() == true) {
return false
}
@@ -252,16 +252,17 @@ fun fastCheckIsNullabilityApplied(lightElement: KtLightElement<*, PsiModifierLis
if (annotatedElement.parent.parent is KtPrimaryConstructor) return false
}
val parent = annotatedElement.parent.parent
if (parent is KtModifierListOwner && parent !is KtPrimaryConstructor && parent.isPrivate()) return false
if (parent is KtPropertyAccessor) {
val propertyOfAccessor = parent.parent
if (propertyOfAccessor is KtProperty && propertyOfAccessor.isPrivate()) return false
when (val parent = annotatedElement.parent.parent) {
is KtConstructor<*> -> {
if (lightElement is KtLightParameter && parent.isPrivate()) return false
}
is KtNamedFunction -> {
return !parent.isPrivate()
}
is KtPropertyAccessor -> {
return (parent.parent as? KtProperty)?.isPrivate() != true
}
}
} else {
// private properties
if ((annotatedElement as? KtModifierListOwner)?.isPrivate() == true) return false
}
return true

View File

@@ -14,4 +14,6 @@ class Test(@get:MyAnnotation @set:MyAnnotation2 @setparam:MyAnnotation3 @propert
var @receiver:MyAnnotation7 Int.fooP
get() = Unit
set(value) {}
}
}
// FIR_COMPARISON

View File

@@ -3,6 +3,7 @@ public final class B /* p.B*/ {
public static final class A /* p.B.A*/ implements p.I {
@org.jetbrains.annotations.NotNull()
private final p.I f;
public A(@org.jetbrains.annotations.NotNull() p.I);// .ctor(p.I)

View File

@@ -1,4 +1,5 @@
public final class B /* p.B*/ implements p.I {
@org.jetbrains.annotations.NotNull()
private final p.I f;
public B(@org.jetbrains.annotations.NotNull() p.I);// .ctor(p.I)

View File

@@ -1,12 +1,15 @@
public final class A /* A*/ {
private final int i;
@org.jetbrains.annotations.NotNull()
private final java.lang.String i$1;
@org.jetbrains.annotations.NotNull()
private final java.lang.String j$1;
@org.jetbrains.annotations.NotNull()
private final java.lang.String j;
private final int i;
@org.jetbrains.annotations.NotNull()
public final java.lang.String g(int, double);// g(int, double)

View File

@@ -8,10 +8,11 @@ public abstract interface TraitClassObjectField /* TraitClassObjectField*/ {
public static final class Companion /* TraitClassObjectField.Companion*/ {
@org.jetbrains.annotations.Nullable()
public static final java.lang.String x = "" /* initializer type: java.lang.String */ /* constant value */;
private static final java.lang.String y;
@org.jetbrains.annotations.Nullable()
public static final java.lang.String x = "" /* initializer type: java.lang.String */ /* constant value */;
private Companion();// .ctor()
}}

View File

@@ -2,10 +2,11 @@ public final class SmartSet /* SmartSet*/<T> extends kotlin.collections.Abstrac
@org.jetbrains.annotations.NotNull()
public static final SmartSet.Companion Companion;
private int size;
@org.jetbrains.annotations.Nullable()
private java.lang.Object data;
private int size;
private static final int ARRAY_THRESHOLD;
@kotlin.jvm.JvmStatic()

View File

@@ -2,6 +2,9 @@ public final class Class /* Class*/ {
@org.jetbrains.annotations.NotNull()
private final java.lang.String notNullVal;
@org.jetbrains.annotations.NotNull()
private final java.lang.String privateNN;
@org.jetbrains.annotations.NotNull()
private java.lang.String notNullVar;
@@ -9,11 +12,10 @@ public final class Class /* Class*/ {
private final java.lang.String nullableVal;
@org.jetbrains.annotations.Nullable()
private java.lang.String nullableVar;
private final java.lang.String privateN;
private final java.lang.String privateNN;
@org.jetbrains.annotations.Nullable()
private java.lang.String nullableVar;
public java.lang.String lateInitVar;

View File

@@ -5,6 +5,7 @@ public final class ClassObjectField /* ClassObjectField*/ {
@org.jetbrains.annotations.Nullable()
private static final java.lang.String x;
@org.jetbrains.annotations.Nullable()
private static final java.lang.String y;
public ClassObjectField();// .ctor()

View File

@@ -4,3 +4,5 @@ class ClassWithConstructorAndProperties(
val nullable: String?,
val notNull: String
)
// FIR_COMPARISON

View File

@@ -2,6 +2,9 @@ public final class FileFacadeKt /* FileFacadeKt*/ {
@org.jetbrains.annotations.NotNull()
private static final java.lang.String notNullVal;
@org.jetbrains.annotations.NotNull()
private static final java.lang.String privateNn;
@org.jetbrains.annotations.NotNull()
private static java.lang.String notNullVar;
@@ -9,11 +12,10 @@ public final class FileFacadeKt /* FileFacadeKt*/ {
private static final java.lang.String nullableVal;
@org.jetbrains.annotations.Nullable()
private static java.lang.String nullableVar;
private static final java.lang.String privateN;
private static final java.lang.String privateNn;
@org.jetbrains.annotations.Nullable()
private static java.lang.String nullableVar;
@org.jetbrains.annotations.NotNull()
@org.jetbrains.annotations.Nullable()

View File

@@ -33,4 +33,6 @@ var nullableVarWithGetSet: String?
private val privateNn: String = { "" }()
private val privateN: String? = { "" }()
private fun privateFun(a: String, b: String?): String? = null
private fun privateFun(a: String, b: String?): String? = null
// FIR_COMPARISON

View File

@@ -1,4 +1,5 @@
public final class Prop /* Prop*/ {
@org.jetbrains.annotations.NotNull()
private final java.lang.Object someProp;
public Prop();// .ctor()

View File

@@ -1320,8 +1320,8 @@ fun main(args: Array<String>) {
testClass<AbstractIdeCompiledLightClassTest> {
model(
"asJava/lightClasses",
excludeDirs = listOf("local", "compilationErrors", "ideRegression"),
pattern = KT_OR_KTS_WITHOUT_DOTS_IN_NAME
excludeDirs = listOf("local", "compilationErrors", "ideRegression", "script"),
pattern = KT_WITHOUT_DOTS_IN_NAME
)
}
}

View File

@@ -885,7 +885,7 @@ fun main(args: Array<String>) {
}
testClass<AbstractIdeCompiledLightClassTest> {
model("asJava/lightClasses", excludeDirs = listOf("local", "compilationErrors", "ideRegression"), pattern = KT_OR_KTS_WITHOUT_DOTS_IN_NAME)
model("asJava/lightClasses", excludeDirs = listOf("local", "compilationErrors", "ideRegression", "script"), pattern = KT_WITHOUT_DOTS_IN_NAME)
}
}

View File

@@ -83,7 +83,7 @@ internal class FirLightFieldForPropertySymbol(
modifiers.add(PsiModifier.VOLATILE)
}
val nullability = if (visibility != PsiModifier.PRIVATE && !(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit))
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit))
propertySymbol.annotatedType.type.getTypeNullability(propertySymbol, FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE)
else NullabilityType.Unknown

View File

@@ -26,7 +26,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInLightClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true, "local", "compilationErrors", "ideRegression");
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), null, true, "local", "compilationErrors", "ideRegression", "script");
}
@TestMetadata("AnnotatedParameterInEnumConstructor.kt")
@@ -178,7 +178,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInDelegation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("Function.kt")
@@ -201,7 +201,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInFacades() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("AllPrivate.kt")
@@ -234,7 +234,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInNullabilityAnnotations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("Class.kt")
@@ -337,7 +337,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInObject() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("SimpleObject.kt")
@@ -355,7 +355,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
}
public void testAllFilesPresentInPublicField() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("CompanionObject.kt")
@@ -368,27 +368,4 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight
runTest("compiler/testData/asJava/lightClasses/publicField/Simple.kt");
}
}
@TestMetadata("compiler/testData/asJava/lightClasses/script")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Script extends AbstractIdeCompiledLightClassTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInScript() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/asJava/lightClasses/script"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("HelloWorld.kts")
public void testHelloWorld() throws Exception {
runTest("compiler/testData/asJava/lightClasses/script/HelloWorld.kts");
}
@TestMetadata("InnerClasses.kts")
public void testInnerClasses() throws Exception {
runTest("compiler/testData/asJava/lightClasses/script/InnerClasses.kts");
}
}
}

View File

@@ -97,13 +97,6 @@ org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDepende
org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependenciesSamePackageWithTests, Temporary muted due to problems with IC and JVM IR backend,,
org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependenciesWrongInternalFromTests, Temporary muted due to problems with IC and JVM IR backend,,
org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependencyWithReferenceToOldVersionLib, Temporary muted due to problems with IC and JVM IR backend,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testClass, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testClassObjectField, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testFileFacade, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Script.testHelloWorld, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Script.testInnerClasses, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegatedNested, KT-44472,,
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegation, KT-44472,,
org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAdded, KT-44844 fixed in IDEA 212,,
org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAddedSamAdapter, KT-44844 fixed in IDEA 212,,
org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodSignatureChanged, KT-44844 fixed in IDEA 212,,
1 Test key Issue State (optional: MUTE or FAIL) Status (optional: FLAKY)
97 org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependenciesSamePackageWithTests Temporary muted due to problems with IC and JVM IR backend
98 org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependenciesWrongInternalFromTests Temporary muted due to problems with IC and JVM IR backend
99 org.jetbrains.kotlin.jps.build.KotlinJpsBuildTestIncremental.testCircularDependencyWithReferenceToOldVersionLib Temporary muted due to problems with IC and JVM IR backend
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testClass KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testClassObjectField KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.NullabilityAnnotations.testFileFacade KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Script.testHelloWorld KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.Script.testInnerClasses KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegatedNested KT-44472
org.jetbrains.kotlin.idea.caches.resolve.IdeCompiledLightClassTestGenerated.testDelegation KT-44472
100 org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAdded KT-44844 fixed in IDEA 212
101 org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodAddedSamAdapter KT-44844 fixed in IDEA 212
102 org.jetbrains.kotlin.jps.build.IncrementalJvmJpsTestGenerated.WithJava.JavaUsedInKotlin.SamConversions.testMethodSignatureChanged KT-44844 fixed in IDEA 212