Use direct field access to trivial class properties
#KT-3845 Fixed
This commit is contained in:
@@ -273,7 +273,7 @@ public class JvmCodegenUtil {
|
||||
if (accessor == null) return true;
|
||||
|
||||
// If the accessor is non-default (i.e. it has some code) we should call that accessor and not use direct access
|
||||
if (!accessor.isDefault()) return false;
|
||||
if (accessor.hasBody()) return false;
|
||||
|
||||
// If the accessor is private or final, it can't be overridden in the subclass and thus we can use direct access
|
||||
return property.getVisibility() == Visibilities.PRIVATE || accessor.getModality() == FINAL;
|
||||
|
||||
@@ -10,7 +10,7 @@ class A {
|
||||
|
||||
class B {
|
||||
var foo = 1
|
||||
private set
|
||||
private set(value) { $foo = value }
|
||||
|
||||
fun foo() {
|
||||
foo = 2
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
class Example
|
||||
{
|
||||
var a1 = 0
|
||||
|
||||
public var a2: Int = 0
|
||||
|
||||
private var a3 = 0
|
||||
|
||||
|
||||
var b1 = 0
|
||||
private set
|
||||
|
||||
var b2 = 0
|
||||
internal set
|
||||
|
||||
var b3 = 0
|
||||
set
|
||||
|
||||
public var b4: Int = 0
|
||||
public set
|
||||
|
||||
private var b5 = 0
|
||||
private set
|
||||
|
||||
|
||||
{
|
||||
a1 = 1
|
||||
a2 = 1
|
||||
a3 = 1
|
||||
|
||||
b1 = 1
|
||||
b2 = 1
|
||||
b3 = 1
|
||||
b4 = 1
|
||||
b5 = 1
|
||||
}
|
||||
}
|
||||
|
||||
// Every property should be accessed directly in this example because they all are final class properties with default accessors
|
||||
// 0 INVOKESPECIAL Example\.set
|
||||
// 0 INVOKEVIRTUAL Example\.set
|
||||
@@ -112,6 +112,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
doTest("compiler/testData/codegen/bytecodeText/kt2887.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt3845.kt")
|
||||
public void testKt3845() throws Exception {
|
||||
doTest("compiler/testData/codegen/bytecodeText/kt3845.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt5016.kt")
|
||||
public void testKt5016() throws Exception {
|
||||
doTest("compiler/testData/codegen/bytecodeText/kt5016.kt");
|
||||
|
||||
Reference in New Issue
Block a user