Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix statics construction #1495

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
val executionResult = convertToExecutionResult(concreteResult, returnClassId)

val stateAfterParametersWithThis = constructParameters(params)
val stateAfterStatics = constructStatics(statics.keys/* + traceHandler.computePutStatics()*/)
val stateAfterStatics = constructStatics(stateBefore, statics)
val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) {
null to stateAfterParametersWithThis
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.utbot.common.withAccessibility
import org.utbot.framework.concrete.constructors.UtCompositeModelStrategy
import org.utbot.framework.concrete.constructors.UtModelConstructor
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.EnvironmentModels
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.TimeoutException
import org.utbot.framework.plugin.api.UtConcreteValue
Expand Down Expand Up @@ -58,11 +59,20 @@ class ModelConstructionContext(
constructor.construct(it.value, it.clazz.id)
}

fun constructStatics(staticFields: Set<FieldId>): Map<FieldId, UtModel> =
staticFields.associateWith { fieldId ->
fun constructStatics(
stateBefore: EnvironmentModels,
staticFields: Map<FieldId, UtConcreteValue<*>>
): Map<FieldId, UtModel> =
staticFields.keys.associateWith { fieldId ->
fieldId.jField.run {
val computedValue = withAccessibility { get(null) }
constructor.construct(computedValue, fieldId.type)
val knownModel = stateBefore.statics[fieldId]
val knownValue = staticFields[fieldId]?.value
if (knownModel != null && knownValue != null && knownValue == computedValue) {
knownModel
} else {
constructor.construct(computedValue, fieldId.type)
}
}
}

Expand Down