[K2] Disappeared OPT_IN_USAGE_ERROR for a data class property during the destructuring declaration
^KT-62450
This commit is contained in:
committed by
Space Team
parent
dfdd86da1f
commit
9ad4cf4c55
+6
@@ -40512,6 +40512,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("diffrentModules.kt")
|
||||||
|
public void testDiffrentModules() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/diffrentModules.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("duration.kt")
|
@TestMetadata("duration.kt")
|
||||||
public void testDuration() throws Exception {
|
public void testDuration() throws Exception {
|
||||||
|
|||||||
+6
@@ -40512,6 +40512,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("diffrentModules.kt")
|
||||||
|
public void testDiffrentModules() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/diffrentModules.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("duration.kt")
|
@TestMetadata("duration.kt")
|
||||||
public void testDuration() throws Exception {
|
public void testDuration() throws Exception {
|
||||||
|
|||||||
+6
@@ -40512,6 +40512,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("diffrentModules.kt")
|
||||||
|
public void testDiffrentModules() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/diffrentModules.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("duration.kt")
|
@TestMetadata("duration.kt")
|
||||||
public void testDuration() throws Exception {
|
public void testDuration() throws Exception {
|
||||||
|
|||||||
+6
@@ -40626,6 +40626,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("diffrentModules.kt")
|
||||||
|
public void testDiffrentModules() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/diffrentModules.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("duration.kt")
|
@TestMetadata("duration.kt")
|
||||||
public void testDuration() throws Exception {
|
public void testDuration() throws Exception {
|
||||||
|
|||||||
+15
@@ -7,14 +7,18 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.KtSourceElement
|
import org.jetbrains.kotlin.KtSourceElement
|
||||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.*
|
import org.jetbrains.kotlin.fir.analysis.checkers.*
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.primaryConstructorSymbol
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.nameOrSpecialName
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||||
import org.jetbrains.kotlin.fir.references.resolved
|
import org.jetbrains.kotlin.fir.references.resolved
|
||||||
@@ -32,6 +36,7 @@ import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
|||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.DataClassResolver
|
||||||
import org.jetbrains.kotlin.resolve.checkers.OptInNames
|
import org.jetbrains.kotlin.resolve.checkers.OptInNames
|
||||||
import org.jetbrains.kotlin.utils.SmartSet
|
import org.jetbrains.kotlin.utils.SmartSet
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
@@ -207,6 +212,16 @@ object FirOptInUsageBaseChecker {
|
|||||||
valueParameters.forEach {
|
valueParameters.forEach {
|
||||||
it.returnTypeRef.coneType.addExperimentalities(context, result, visited)
|
it.returnTypeRef.coneType.addExperimentalities(context, result, visited)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handling data class 'componentN' function
|
||||||
|
if (parentClassSymbol?.isData == true && DataClassResolver.isComponentLike(this.nameOrSpecialName) && parentClassSymbol.classKind == ClassKind.CLASS) {
|
||||||
|
val componentNIndex = DataClassResolver.getComponentIndex(this.nameOrSpecialName.identifier)
|
||||||
|
val valueParameters = parentClassSymbol.primaryConstructorSymbol(context.session)?.valueParameterSymbols
|
||||||
|
val valueParameter = valueParameters?.getOrNull(componentNIndex - 1)
|
||||||
|
val properties = parentClassSymbol.declarationSymbols.filterIsInstance<FirPropertySymbol>()
|
||||||
|
val property = properties.firstOrNull { it.name == valueParameter?.name }
|
||||||
|
property?.loadExperimentalities(context, result, visited, fromSetter = false, dispatchReceiverType, fromSupertype = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromSetter && symbol is FirPropertySymbol) {
|
if (fromSetter && symbol is FirPropertySymbol) {
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// !OPT_IN: kotlin.RequiresOptIn
|
||||||
|
// FILE: api.kt
|
||||||
|
|
||||||
|
|
||||||
|
// MODULE: A
|
||||||
|
package main
|
||||||
|
|
||||||
|
@kotlin.RequiresOptIn
|
||||||
|
annotation class Marker
|
||||||
|
|
||||||
|
data class DataClass(@property:Marker val x: Int)
|
||||||
|
|
||||||
|
// MODULE: B(A)
|
||||||
|
package main
|
||||||
|
|
||||||
|
fun test(d: DataClass) {
|
||||||
|
val (<!OPT_IN_USAGE_ERROR!>x<!>) = d
|
||||||
|
val c = d.<!OPT_IN_USAGE_ERROR!>component1<!>()
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// !OPT_IN: kotlin.RequiresOptIn
|
||||||
|
// FILE: api.kt
|
||||||
|
|
||||||
|
|
||||||
|
// MODULE: A
|
||||||
|
package main
|
||||||
|
|
||||||
|
@kotlin.RequiresOptIn
|
||||||
|
annotation class Marker
|
||||||
|
|
||||||
|
data class DataClass(@property:Marker val x: Int)
|
||||||
|
|
||||||
|
// MODULE: B(A)
|
||||||
|
package main
|
||||||
|
|
||||||
|
fun test(d: DataClass) {
|
||||||
|
val (x) = d
|
||||||
|
val c = d.component1()
|
||||||
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@ data class DataClass(@property:Marker val x: Int)
|
|||||||
fun useDataClass(d: DataClass) {
|
fun useDataClass(d: DataClass) {
|
||||||
// Should have error in both
|
// Should have error in both
|
||||||
d.<!OPT_IN_USAGE_ERROR!>x<!>
|
d.<!OPT_IN_USAGE_ERROR!>x<!>
|
||||||
val (x) = d
|
val (<!OPT_IN_USAGE_ERROR!>x<!>) = d
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias My = <!OPT_IN_USAGE_ERROR!>Some<!>
|
typealias My = <!OPT_IN_USAGE_ERROR!>Some<!>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ data class DataClass(@property:Marker val x: Int)
|
|||||||
fun useDataClass(d: DataClass) {
|
fun useDataClass(d: DataClass) {
|
||||||
// Should have error in both
|
// Should have error in both
|
||||||
d.<!OPT_IN_USAGE_ERROR!>x<!>
|
d.<!OPT_IN_USAGE_ERROR!>x<!>
|
||||||
val (x) = d
|
val (<!OPT_IN_USAGE_ERROR!>x<!>) = d
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias My = <!OPT_IN_USAGE_ERROR!>Some<!>
|
typealias My = <!OPT_IN_USAGE_ERROR!>Some<!>
|
||||||
|
|||||||
Generated
+6
@@ -42548,6 +42548,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("diffrentModules.kt")
|
||||||
|
public void testDiffrentModules() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/diffrentModules.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("duration.kt")
|
@TestMetadata("duration.kt")
|
||||||
public void testDuration() throws Exception {
|
public void testDuration() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user