FIR2IR strip annotations from IrConst type

This commit is contained in:
Dmitry Petrov
2021-11-22 17:51:07 +03:00
committed by Space
parent 0048540652
commit 2a263eca65
8 changed files with 20 additions and 8 deletions
@@ -261,7 +261,8 @@ fun <T> FirConstExpression<T>.toIrConst(irType: IrType): IrConst<T> {
} as T ?: value
IrConstImpl(
startOffset, endOffset,
irType,
// Strip all annotations (including special annotations such as @EnhancedNullability) from constant type
irType.removeAnnotations(),
kind, value
)
}
@@ -71,6 +71,18 @@ fun IrType.removeAnnotations(predicate: (IrConstructorCall) -> Boolean): IrType
this
}
fun IrType.removeAnnotations(): IrType =
when (this) {
is IrSimpleType ->
toBuilder().apply {
annotations = emptyList()
}.buildSimpleType()
is IrDynamicType ->
IrDynamicTypeImpl(null, emptyList(), Variance.INVARIANT)
else ->
this
}
val IrType.classifierOrFail: IrClassifierSymbol
get() = cast<IrSimpleType>().classifier
@@ -1,6 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: AE: Argument 1: expected R, but found I at INVOKEINTERFACE Sam.get
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
@@ -1,9 +1,6 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: ANDROID
// ^ uses API not implemented on minSdkVersion 19
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: fir2ir creates an IrConst(value=2, type=@EnhancedNullability Int), which
// the backend generates as an int instead of Integer
// WITH_STDLIB
// JVM_TARGET: 1.8
// FULL_JDK
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: AnalyzerException: Argument 1: expected R, but found I
// TARGET_BACKEND: JVM
// FILE: J.java
@@ -40,6 +40,8 @@ FILE fqName:<root> fileName:/enhancedNullability.kt
s: CALL 'public open fun nullString (): @[FlexibleNullability] kotlin.String? declared in <root>.J' type=@[FlexibleNullability] kotlin.String? origin=null
CALL 'public open fun use (s: @[EnhancedNullability] kotlin.String): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
s: CALL 'public open fun notNullString (): @[EnhancedNullability] kotlin.String declared in <root>.J' type=@[EnhancedNullability] kotlin.String origin=null
CALL 'public open fun use (x: @[EnhancedNullability] kotlin.Int): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
x: CONST Int type=kotlin.Int value=42
FUN name:testLocalVarUse visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:ns type:@[FlexibleNullability] kotlin.String? [val]
@@ -21,6 +21,7 @@ val testGlobalValGetter get() = J.notNullString()
fun testJUse() {
J.use(J.nullString())
J.use(J.notNullString())
J.use(42)
}
fun testLocalVarUse() {
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.*;
public class J {
public static void use(@NotNull String s) {}
public static void use(@NotNull Integer x) {}
public static String nullString() { return null; }
public static @NotNull String notNullString() { return null; }
}
@@ -25,6 +25,7 @@ val testGlobalValGetter: String
fun testJUse() {
use(s = nullString())
use(s = notNullString())
use(x = 42)
}
fun testLocalVarUse() {
@@ -33,3 +34,4 @@ fun testLocalVarUse() {
val nns: String = notNullString() /*!! String */
use(s = nns)
}