[FIR] Fix CANNOT_BE_IMPORTED for java static methods/variables
This commit is contained in:
committed by
TeamCityServer
parent
2b161581ca
commit
371452d49a
+6
@@ -11645,6 +11645,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportStaticFunctionWithNonStaticSibling.kt")
|
||||
public void testImportStaticFunctionWithNonStaticSibling() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportStaticFunctionWithNonStaticSibling.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportTwoTimes.kt")
|
||||
public void testImportTwoTimes() throws Exception {
|
||||
|
||||
+6
@@ -11645,6 +11645,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportStaticFunctionWithNonStaticSibling.kt")
|
||||
public void testImportStaticFunctionWithNonStaticSibling() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportStaticFunctionWithNonStaticSibling.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportTwoTimes.kt")
|
||||
public void testImportTwoTimes() throws Exception {
|
||||
|
||||
+14
-17
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.resolve.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.isStatic
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
@@ -56,11 +57,8 @@ object FirImportsChecker : FirFileChecker() {
|
||||
if (classId != null) {
|
||||
val classFir = classId.resolveToClass(context) ?: return
|
||||
if (classFir.classKind.isSingleton) return
|
||||
|
||||
val illegalImport = classFir.hasFunctionOrProperty(context, importedName) {
|
||||
it is FirSimpleFunction && !it.isStatic || it is FirProperty
|
||||
}
|
||||
if (illegalImport) {
|
||||
|
||||
if (!classFir.canBeImported(context, importedName)) {
|
||||
reporter.reportOn(import.source, FirErrors.CANNOT_BE_IMPORTED, importedName, context)
|
||||
}
|
||||
} else {
|
||||
@@ -148,26 +146,25 @@ object FirImportsChecker : FirFileChecker() {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun FirRegularClass.hasFunctionOrProperty(
|
||||
private fun FirRegularClass.canBeImported(
|
||||
context: CheckerContext,
|
||||
name: Name,
|
||||
predicate: (FirDeclaration) -> Boolean
|
||||
name: Name
|
||||
): Boolean {
|
||||
var result = false
|
||||
var hasStatic = false
|
||||
var hasIllegal = false
|
||||
val scope = context.session.declaredMemberScope(this)
|
||||
scope.processFunctionsByName(name) { sym ->
|
||||
if (!result) {
|
||||
result = predicate(sym.fir)
|
||||
}
|
||||
if (sym.isStatic) hasStatic = true
|
||||
else hasIllegal = true
|
||||
}
|
||||
if (result) return true
|
||||
if (hasStatic) return true
|
||||
if (hasIllegal) return false
|
||||
|
||||
scope.processPropertiesByName(name) { sym ->
|
||||
if (!result) {
|
||||
result = predicate(sym.fir)
|
||||
}
|
||||
if (sym.isStatic) hasStatic = true
|
||||
else hasIllegal = true
|
||||
}
|
||||
|
||||
return result
|
||||
return hasStatic || !hasIllegal
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// FIR_IDENTICAL
|
||||
//FILE:a/Foo.java
|
||||
package a;
|
||||
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
|
||||
}
|
||||
|
||||
public static void bar(String arg) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//FILE:test.kt
|
||||
package b
|
||||
|
||||
import a.Foo.bar
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
public open class Foo {
|
||||
public constructor Foo()
|
||||
public open fun bar(): kotlin.Unit
|
||||
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
|
||||
|
||||
// Static members
|
||||
public open fun bar(/*0*/ arg: kotlin.String!): kotlin.Unit
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -11651,6 +11651,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportStaticFunctionWithNonStaticSibling.kt")
|
||||
public void testImportStaticFunctionWithNonStaticSibling() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportStaticFunctionWithNonStaticSibling.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ImportTwoTimes.kt")
|
||||
public void testImportTwoTimes() throws Exception {
|
||||
|
||||
+5
@@ -10152,6 +10152,11 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ImportStaticFunctionWithNonStaticSibling.kt")
|
||||
public void testImportStaticFunctionWithNonStaticSibling() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportStaticFunctionWithNonStaticSibling.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ImportTwoTimes.kt")
|
||||
public void testImportTwoTimes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/imports/ImportTwoTimes.kt");
|
||||
|
||||
Reference in New Issue
Block a user