[FIR] Ensure NO_COMPANION_OBJECT is reported for typealiases
^KT-55733 Fixed ^KT-55186 Fixed
This commit is contained in:
committed by
Space Team
parent
609f417a13
commit
0e1350f464
+6
@@ -501,6 +501,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/kt54587_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55733.kt")
|
||||
public void testKt55733() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("LValueAssignment.kt")
|
||||
public void testLValueAssignment() throws Exception {
|
||||
|
||||
+6
@@ -501,6 +501,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/kt54587_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55733.kt")
|
||||
public void testKt55733() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("LValueAssignment.kt")
|
||||
public void testLValueAssignment() throws Exception {
|
||||
|
||||
+6
@@ -501,6 +501,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/kt54587_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55733.kt")
|
||||
public void testKt55733() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("LValueAssignment.kt")
|
||||
public void testLValueAssignment() throws Exception {
|
||||
|
||||
+14
-4
@@ -5,14 +5,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.fullyExpandedClass
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.isUnit
|
||||
|
||||
object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
|
||||
@@ -23,14 +27,20 @@ object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
|
||||
if (lastGetClass?.argument === expression) return
|
||||
// Note: if it's real Unit, it will be filtered by ClassKind.OBJECT check below
|
||||
if (!expression.typeRef.isUnit) return
|
||||
expression.symbol.reportErrorOn(expression.source, context, reporter)
|
||||
}
|
||||
|
||||
when (val symbol = expression.symbol) {
|
||||
private fun FirBasedSymbol<*>?.reportErrorOn(source: KtSourceElement?, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
when (this) {
|
||||
is FirRegularClassSymbol -> {
|
||||
if (symbol.classKind == ClassKind.OBJECT) return
|
||||
reporter.reportOn(expression.source, FirErrors.NO_COMPANION_OBJECT, symbol, context)
|
||||
if (classKind == ClassKind.OBJECT) return
|
||||
reporter.reportOn(source, FirErrors.NO_COMPANION_OBJECT, this, context)
|
||||
}
|
||||
is FirTypeAliasSymbol -> {
|
||||
fullyExpandedClass(context.session)?.reportErrorOn(source, context, reporter)
|
||||
}
|
||||
null -> {
|
||||
reporter.reportOn(expression.source, FirErrors.EXPRESSION_EXPECTED_PACKAGE_FOUND, context)
|
||||
reporter.reportOn(source, FirErrors.EXPRESSION_EXPECTED_PACKAGE_FOUND, context)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
fun main() {
|
||||
val appendable = <!NO_COMPANION_OBJECT!>Appendable<!>
|
||||
val stringBuilder = <!NO_COMPANION_OBJECT!>StringBuilder<!>
|
||||
val exception = <!NO_COMPANION_OBJECT!>IllegalStateException<!>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// +JDK
|
||||
|
||||
typealias Exn = java.lang.Exception
|
||||
|
||||
fun test() {
|
||||
throw Exn
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// +JDK
|
||||
|
||||
typealias Exn = java.lang.Exception
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
interface IFoo
|
||||
|
||||
typealias Test = IFoo
|
||||
|
||||
val testAsFunction = <!RESOLUTION_TO_CLASSIFIER!>Test<!>()
|
||||
val testAsValue = Test
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
interface IFoo
|
||||
|
||||
typealias Test = IFoo
|
||||
|
||||
Generated
+6
@@ -501,6 +501,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/kt54587_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55733.kt")
|
||||
public void testKt55733() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("LValueAssignment.kt")
|
||||
public void testLValueAssignment() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user