Enum.valueOf throws inconsistent exception across multiple platforms #KT-35116
This commit is contained in:
committed by
Space Team
parent
d6867917c9
commit
295fdc36ce
@@ -206,6 +206,9 @@ abstract class Symbols(
|
||||
open val throwISE: IrSimpleFunctionSymbol
|
||||
get() = error("throwISE is not implemented")
|
||||
|
||||
open val throwIAE: IrSimpleFunctionSymbol
|
||||
get() = error("throwIAE is not implemented")
|
||||
|
||||
abstract val stringBuilder: IrClassSymbol
|
||||
|
||||
abstract val defaultConstructorMarker: IrClassSymbol
|
||||
|
||||
@@ -219,6 +219,9 @@ class JsIrBackendContext(
|
||||
override val throwISE: IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
|
||||
|
||||
override val throwIAE: IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))).single())
|
||||
|
||||
override val stringBuilder
|
||||
get() = TODO("not implemented")
|
||||
override val coroutineImpl =
|
||||
@@ -325,9 +328,6 @@ class JsIrBackendContext(
|
||||
val setPropertiesToThrowableInstanceSymbol =
|
||||
symbolTable.referenceSimpleFunction(getJsInternalFunction("setPropertiesToThrowableInstance"))
|
||||
|
||||
val throwISEsymbol = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
|
||||
val throwIAEsymbol = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))).single())
|
||||
|
||||
override val suiteFun = getFunctions(FqName("kotlin.test.suite")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
override val testFun = getFunctions(FqName("kotlin.test.test")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
|
||||
+4
-2
@@ -501,7 +501,7 @@ class EnumSyntheticFunctionsAndPropertiesLowering(
|
||||
return null
|
||||
}
|
||||
|
||||
private val throwISESymbol = context.ir.symbols.throwISE
|
||||
private val throwIAESymbol = context.ir.symbols.throwIAE
|
||||
|
||||
private fun createEnumEntriesBody(entriesGetter: IrFunction, enumClass: IrClass): IrBlockBody {
|
||||
val entriesField = enumClass.buildEntriesField()
|
||||
@@ -548,7 +548,9 @@ class EnumSyntheticFunctionsAndPropertiesLowering(
|
||||
)
|
||||
} memoryOptimizedPlus irElseBranch(irBlock {
|
||||
+irCall(irClass.initEntryInstancesFun!!)
|
||||
+irCall(throwISESymbol)
|
||||
+irCall(throwIAESymbol).apply {
|
||||
putValueArgument(0, irString("No enum constant ${nameParameter.name.identifier}."))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ class PropertyReferenceLowering(private val context: JsIrBackendContext) : BodyL
|
||||
private val localDelegateBuilderSymbol = context.klocalDelegateBuilder
|
||||
private val jsClassSymbol = context.intrinsics.jsClass
|
||||
|
||||
private val throwISE = context.throwISEsymbol
|
||||
private val throwISE = context.ir.symbols.throwISE
|
||||
|
||||
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
||||
val currentParent = container as? IrDeclarationParent ?: container.parent
|
||||
|
||||
@@ -83,7 +83,7 @@ class WasmSymbols(
|
||||
override val throwNullPointerException = getInternalFunction("THROW_NPE")
|
||||
override val throwISE = getInternalFunction("THROW_ISE")
|
||||
override val throwTypeCastException = getInternalFunction("THROW_CCE")
|
||||
val throwIAE = getInternalFunction("THROW_IAE")
|
||||
override val throwIAE = getInternalFunction("THROW_IAE")
|
||||
val throwNoBranchMatchedException =
|
||||
getInternalFunction("throwNoBranchMatchedException")
|
||||
override val throwUninitializedPropertyAccessException =
|
||||
|
||||
+14
-1
@@ -1,5 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.assertSame
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
enum class E { OK }
|
||||
|
||||
fun <T> id(x: T) = x
|
||||
|
||||
fun box() = enumValueOf<E>(id("OK")).name
|
||||
fun box(): String {
|
||||
assertSame(E.OK, E.valueOf("OK"))
|
||||
assertSame(E.OK, enumValueOf<E>("OK"))
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { E.valueOf("NO") }
|
||||
assertFailsWith<IllegalArgumentException> { enumValueOf<E>("NO") }
|
||||
|
||||
return enumValueOf<E>(id("OK")).name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user