Skip to content

Treat Boolean accessor methods as properties in Kotlin codegen #1083

Open
@volivan239

Description

@volivan239

Description

If Java code has a private boolean field x with public getter declared as isX (and, optionally, setter setX) Kotlin will treat it as property isX and will allow only direct property access. (See docs for more info).

Currently we still think of this as of private property and use refleciton even though it is unnecessary.

To Reproduce

Create a Java class

public class KotlinExample {
    private boolean x;
    public boolean isX() {
        return x;
    }
    public void setX(boolean value) {
        x = value;
    }
}

Then create a Kotlin class

class TestExample {
    fun f(a: KotlinExample): KotlinExample {
        a.isX = true;
        return a;
    }
}

and launch action on it.

Expected behavior

In tests field x is set using direct access to property isX.

Actual behavior

Generated tests will use reflection to set field in instances of KotlinExample

Additional context

Strongly related to #496

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

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions