From 4c77f96c8988a3127b3c37b883edb8f93dc1209d Mon Sep 17 00:00:00 2001 From: IlyaMuravjov <71839386+IlyaMuravjov@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:35:51 +0300 Subject: [PATCH] Store `enumValue.name` in `enumValueName` (not `enumValue.toString()`) (#102) --- .../testcase/descriptor/Descriptor2ValueConverter.kt | 2 +- .../testcase/descriptor/Value2DescriptorConverter.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Descriptor2ValueConverter.kt b/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Descriptor2ValueConverter.kt index 0e942e889c..36002bab50 100644 --- a/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Descriptor2ValueConverter.kt +++ b/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Descriptor2ValueConverter.kt @@ -96,7 +96,7 @@ class Descriptor2ValueConverter(private val workerClassLoader: ClassLoader) { private fun `enum`(descriptor: UTestEnumValueDescriptor): Any { val klass = descriptor.type.toJavaClass(workerClassLoader) - val enumValue = klass.enumConstants.find { it.toString() == descriptor.enumValueName } + val enumValue = klass.enumConstants.find { (it as Enum<*>).name == descriptor.enumValueName } ?: error("Can't build descriptor for enum") for ((jcField, jcFieldDescr) in descriptor.fields) { val jField = jcField.toJavaField(workerClassLoader) ?: continue diff --git a/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Value2DescriptorConverter.kt b/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Value2DescriptorConverter.kt index e87b52c9ee..9c3e3e3e1e 100644 --- a/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Value2DescriptorConverter.kt +++ b/usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Value2DescriptorConverter.kt @@ -258,11 +258,11 @@ open class Value2DescriptorConverter( ) } - private fun `enum`(value: Any, depth: Int): UTestEnumValueDescriptor { + private fun `enum`(value: Enum<*>, depth: Int): UTestEnumValueDescriptor { val enumValueJcClass = jcClasspath.findClass(value::class.java.name) val jcClass = if (!enumValueJcClass.isEnum) enumValueJcClass.superClass!! else enumValueJcClass val fields = mutableMapOf() - val enumValueName = value.toString() + val enumValueName = value.name val jcType = jcClass.toType() val uTestEnumValueDescriptor = UTestEnumValueDescriptor(jcType, enumValueName, fields, System.identityHashCode(value))