diff --git a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt index ddd63711516..ecb4d71bb5a 100644 --- a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt +++ b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt @@ -167,13 +167,12 @@ class JDIEval( } } - private fun findField(fieldDesc: FieldDescription): Field { - val _class = fieldDesc.ownerType.asReferenceType() - val field = _class.fieldByName(fieldDesc.name) - if (field == null) { - throwBrokenCodeException(NoSuchFieldError("Field not found: $fieldDesc")) + private fun findField(fieldDesc: FieldDescription, receiver: ReferenceType? = null): Field { + for (owner in listOfNotNull(receiver, fieldDesc.ownerType.asReferenceType())) { + owner.fieldByName(fieldDesc.name)?.let { return it } } - return field + + throwBrokenCodeException(NoSuchFieldError("Field not found: $fieldDesc")) } private fun findStaticField(fieldDesc: FieldDescription): Field { @@ -256,26 +255,26 @@ class JDIEval( } override fun getField(instance: Value, fieldDesc: FieldDescription): Value { - val field = findField(fieldDesc) - val obj = instance.jdiObj.checkNull() + val receiver = instance.jdiObj.checkNull() + val field = findField(fieldDesc, receiver.referenceType()) return mayThrow { try { - obj.getValue(field) + receiver.getValue(field) } catch (e: IllegalArgumentException) { throw IllegalArgumentException("Possibly incompatible types: " + "field declaring type = ${field.declaringType()}, " + - "instance type = ${obj.referenceType()}") + "instance type = ${receiver.referenceType()}") } - }.ifFail(field, obj).asValue() + }.ifFail(field, receiver).asValue() } override fun setField(instance: Value, fieldDesc: FieldDescription, newValue: Value) { - val field = findField(fieldDesc) - val obj = instance.jdiObj.checkNull() + val receiver = instance.jdiObj.checkNull() + val field = findField(fieldDesc, receiver.referenceType()) val jdiValue = newValue.asJdiValue(vm, field.type().asType()) - mayThrow { obj.setValue(field, jdiValue) } + mayThrow { receiver.setValue(field, jdiValue) } } fun unboxType(boxedValue: Value, type: Type): Value {