@@ -1487,9 +1487,8 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
14871487 substituteStaticFields(statics, isParametrized = true )
14881488
14891489 // build this instance
1490- thisInstance =
1491- genericExecution.stateBefore.thisInstance?.let {
1492- variableConstructor.getOrCreateVariable(it)
1490+ thisInstance = genericExecution.stateBefore.thisInstance?.let {
1491+ currentMethodParameters[CgParameterKind .ThisInstance ]
14931492 }
14941493
14951494 // build arguments for method under test and parameterized test
@@ -1552,6 +1551,20 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
15521551 val executableUnderTestParameters = testSet.executableId.executable.parameters
15531552
15541553 return mutableListOf<CgParameterDeclaration >().apply {
1554+ // this instance
1555+ genericExecution.stateBefore.thisInstance?.let {
1556+ val type = wrapTypeIfRequired(it.classId)
1557+ val thisInstance = CgParameterDeclaration (
1558+ parameter = declareParameter(
1559+ type = type,
1560+ name = nameGenerator.variableName(type)
1561+ ),
1562+ isReferenceType = true
1563+ )
1564+ this + = thisInstance
1565+ currentMethodParameters[CgParameterKind .ThisInstance ] = thisInstance.parameter
1566+ }
1567+
15551568 // arguments
15561569 for (index in genericExecution.stateBefore.parameters.indices) {
15571570 val argumentName = paramNames[executableUnderTest]?.get(index)
@@ -1663,6 +1676,10 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
16631676 private fun createExecutionArguments (testSet : CgMethodTestSet , execution : UtExecution ): List <CgExpression > {
16641677 val arguments = mutableListOf<CgExpression >()
16651678
1679+ execution.stateBefore.thisInstance?.let {
1680+ arguments + = variableConstructor.getOrCreateVariable(it)
1681+ }
1682+
16661683 for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) {
16671684 val argumentName = paramNames[testSet.executableId]?.get(paramIndex)
16681685 arguments + = variableConstructor.getOrCreateVariable(paramModel, argumentName)
@@ -1673,7 +1690,6 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
16731690 arguments + = variableConstructor.getOrCreateVariable(model, field.name)
16741691 }
16751692
1676-
16771693 val method = currentExecutable!!
16781694 val needsReturnValue = method.returnType != voidClassId
16791695 val containsFailureExecution = containsFailureExecution(testSet)
0 commit comments