Skip to content

Unnecessary reflection used for val properties that can be set via constructor #1190

Description

@volivan239

Description

If constructor has a val property, codegen doesn't use this constructor but instead instantiates class via reflection although it can normally be done without it.

To Reproduce

Launch action on the following class:

classCustomClass(valx:Int) {
funf(): Int {
return x
}
}

Expected behavior

Correct tests are generated, reflection is not used at all.

Actual behavior

Generated tests contain reflection usage.

Visual proofs (screenshots, logs, images)

One of the generated tests:

@Test
funtestF1() {
val customClass = (createInstance("CustomClass") asCustomClass)
setField(customClass, "CustomClass", "x", -255)
val actual = customClass.f()
assertEquals(-255, actual)
}

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a buglang-kotlinIssue is related to Kotlin language support

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions