Skip to content

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

Closed

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)
}

Activity

  1. added
    ctg-bug
    comp-codegen
    on Oct 19, 2022
  2. self-assigned this
    on Oct 19, 2022
  3. moved this to Todo in UTBot Javaon Oct 19, 2022
  4. added
    lang-kotlin
    on Oct 28, 2022
  5. Repository owner moved this from Todo to Done in UTBot Javaon Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp-codegenctg-buglang-kotlin

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions