Skip to content

Incorrect property access rendering in Kotlin #948

Closed as not planned
Closed as not planned
@volivan239

Description

@volivan239

Description

By default, Kotlin generates a private field and getter/setter for each property into bytecode. However, you can't use these getters/setters directly from Kotlin code, instead you should direct access syntax (like direct accessing field in Java). However, code produced by UTBot uses these setters/getters which lead to compilation error.

To Reproduce

Launch action on the following class:

class Sample {
    var x: Int = 3;
    fun f(): Int {
        return x;
    }
}

Expected behavior

Tests are generated correctly (in particular, access to field is written like sample.x = ...)

Actual behavior

Generated tests are not compilable.

Visual proofs (screenshots, logs, images)

Among others, the following test is produced:

@Test
fun testF1() {
    val sample = Sample()
    sample.setX(-255)

    val actual = sample.f()

    assertEquals(-255, actual)
}

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bugstatus-duplicateThis issue or pull request already exists

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions