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:

class CustomClass(val x: Int) {
    fun f(): 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
fun testF1() {
    val customClass = (createInstance("CustomClass") as CustomClass)
    setField(customClass, "CustomClass", "x", -255)
    
    val actual = customClass.f()
      
    assertEquals(-255, actual)
}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions