FIR: Fix exception caused by empty supertypes of java.lang.Object

This commit is contained in:
Denis.Zharkov
2021-10-04 18:23:37 +03:00
committed by TeamCityServer
parent 7eb0fd4762
commit 9d9f191f51
6 changed files with 49 additions and 4 deletions
@@ -5396,6 +5396,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
public void testTypeParameterUse() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/typeParameterUse.kt");
}
@Test
@TestMetadata("UsingObject.kt")
public void testUsingObject() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/UsingObject.kt");
}
}
@Nested
@@ -0,0 +1,14 @@
FILE: UsingObject.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final fun foo(): R|A?| {
^foo Null(null)
}
public final fun main(): R|kotlin/Unit| {
lval w: R|kotlin/Any| = R|/foo|() ?: Q|java/lang|.R|java/lang/Object.Object|()
R|<local>/w|.R|kotlin/Any.hashCode|()
}
@@ -0,0 +1,8 @@
class A
fun foo(): A? = null
fun main() {
val w = foo() ?: java.lang.Object()
w.hashCode()
}
@@ -5396,6 +5396,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
public void testTypeParameterUse() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/typeParameterUse.kt");
}
@Test
@TestMetadata("UsingObject.kt")
public void testUsingObject() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/UsingObject.kt");
}
}
@Nested
@@ -5396,6 +5396,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
public void testTypeParameterUse() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/typeParameterUse.kt");
}
@Test
@TestMetadata("UsingObject.kt")
public void testUsingObject() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/UsingObject.kt");
}
}
@Nested
@@ -33,15 +33,13 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeFlexibleType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.constructClassLikeType
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.structure.*
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.types.Variance.INVARIANT
import org.jetbrains.kotlin.util.OperatorNameConventions
@@ -195,6 +193,13 @@ class FirJavaFacade(
}
}
javaClass.supertypes.mapTo(superTypeRefs) { it.toFirJavaTypeRef(session, javaTypeParameterStack) }
if (superTypeRefs.isEmpty()) {
superTypeRefs.add(
buildResolvedTypeRef {
type = StandardClassIds.Any.constructClassLikeType(emptyArray(), isNullable = false)
}
)
}
val dispatchReceiver = classId.defaultType(typeParameters.map { it.symbol })