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

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

Closed
volivan239 opened this issue Oct 19, 2022 · 0 comments · Fixed by #1240
Closed

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

volivan239 opened this issue Oct 19, 2022 · 0 comments · Fixed by #1240
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support

Comments

@volivan239
Copy link
Collaborator

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)
}
@volivan239 volivan239 added ctg-bug Issue is a bug comp-codegen Issue is related to code generator labels Oct 19, 2022
@volivan239 volivan239 self-assigned this Oct 19, 2022
@volivan239 volivan239 added the lang-kotlin Issue is related to Kotlin language support label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant