Constructors represented "as in Java".
TODO: extract nested initializers somehow.
This commit is contained in:
committed by
Dmitry Petrov
parent
57c1b3e0e2
commit
8528c23194
+10
-3
@@ -2,9 +2,12 @@ FILE /classMembers.kt
|
||||
CLASS CLASS C
|
||||
FUN public constructor C(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Int = ...)
|
||||
BLOCK_BODY
|
||||
INITIALIZE_PROPERTY y
|
||||
INITIALIZE_PROPERTY z
|
||||
INITIALIZE_PROPERTY property
|
||||
SET_BACKING_FIELD y type=kotlin.Unit operator=null
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
SET_BACKING_FIELD z type=kotlin.Unit operator=null
|
||||
GET_VAR z type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
SET_BACKING_FIELD property type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final val y: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
@@ -45,6 +48,8 @@ FILE /classMembers.kt
|
||||
CALL .println type=kotlin.Unit operator=null
|
||||
message: CONST String type=kotlin.String value='2'
|
||||
CLASS CLASS NestedClass
|
||||
FUN public constructor NestedClass()
|
||||
BLOCK_BODY
|
||||
FUN public final fun function(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL .println type=kotlin.Unit operator=null
|
||||
@@ -61,3 +66,5 @@ FILE /classMembers.kt
|
||||
CALL .foo type=kotlin.Unit operator=null
|
||||
$this: THIS public interface NestedInterface type=C.NestedInterface
|
||||
CLASS OBJECT Companion
|
||||
FUN private constructor Companion()
|
||||
BLOCK_BODY
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
open class Base
|
||||
|
||||
class Test : Base {
|
||||
constructor()
|
||||
constructor(xx: Int): super()
|
||||
constructor(xx: Short): this()
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
FILE /delegatingConstructorCallsInSecondaryConstructors.kt
|
||||
CLASS CLASS Base
|
||||
FUN public constructor Base()
|
||||
BLOCK_BODY
|
||||
CLASS CLASS Test
|
||||
FUN public constructor Test()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
FUN public constructor Test(/*0*/ xx: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
FUN public constructor Test(/*0*/ xx: kotlin.Short)
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Test operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class TestInitValFromParameter(val x: Int)
|
||||
|
||||
class TestInitValInClass {
|
||||
val x = 0
|
||||
}
|
||||
|
||||
class TestInitValInInitBlock {
|
||||
val x: Int
|
||||
init {
|
||||
x = 0
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
FILE /initVal.kt
|
||||
CLASS CLASS TestInitValFromParameter
|
||||
FUN public constructor TestInitValFromParameter(/*0*/ x: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
PROPERTY public final val x: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
CLASS CLASS TestInitValInClass
|
||||
FUN public constructor TestInitValInClass()
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final val x: kotlin.Int = 0 getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
CLASS CLASS TestInitValInInitBlock
|
||||
FUN public constructor TestInitValInInitBlock()
|
||||
BLOCK_BODY
|
||||
BLOCK type=kotlin.Unit operator=null
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final val x: kotlin.Int getter=null setter=null
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
class TestInitVarFromParameter(var x: Int)
|
||||
|
||||
class TestInitVarInClass {
|
||||
var x = 0
|
||||
}
|
||||
|
||||
class TestInitVarInInitBlock {
|
||||
var x: Int
|
||||
init {
|
||||
x = 0
|
||||
}
|
||||
}
|
||||
|
||||
class TestInitVarWithCustomSetter {
|
||||
var x = 0
|
||||
set(value) { field = value }
|
||||
}
|
||||
|
||||
class TestInitVarWithCustomSetterWithExplicitCtor {
|
||||
var x: Int
|
||||
set(value) { field = value }
|
||||
|
||||
init {
|
||||
x = 0
|
||||
}
|
||||
|
||||
constructor()
|
||||
}
|
||||
|
||||
class TestInitVarWithCustomSetterInCtor {
|
||||
var x: Int set(value) {
|
||||
field = value
|
||||
}
|
||||
|
||||
constructor() {
|
||||
x = 42
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
FILE /initVar.kt
|
||||
CLASS CLASS TestInitVarFromParameter
|
||||
FUN public constructor TestInitVarFromParameter(/*0*/ x: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
CLASS CLASS TestInitVarInClass
|
||||
FUN public constructor TestInitVarInClass()
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
CLASS CLASS TestInitVarInInitBlock
|
||||
FUN public constructor TestInitVarInInitBlock()
|
||||
BLOCK_BODY
|
||||
BLOCK type=kotlin.Unit operator=null
|
||||
CALL .<set-x> type=kotlin.Unit operator=EQ
|
||||
$this: THIS public final class TestInitVarInInitBlock type=TestInitVarInInitBlock
|
||||
<set-?>: CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=null
|
||||
CLASS CLASS TestInitVarWithCustomSetter
|
||||
FUN public constructor TestInitVarWithCustomSetter()
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=<set-x>
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
PROPERTY_SETTER public final fun <set-x>(/*0*/ value: kotlin.Int): kotlin.Unit property=x
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=EQ
|
||||
GET_VAR value type=kotlin.Int operator=null
|
||||
CLASS CLASS TestInitVarWithCustomSetterWithExplicitCtor
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=<set-x>
|
||||
PROPERTY_SETTER public final fun <set-x>(/*0*/ value: kotlin.Int): kotlin.Unit property=x
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=EQ
|
||||
GET_VAR value type=kotlin.Int operator=null
|
||||
FUN public constructor TestInitVarWithCustomSetterWithExplicitCtor()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=kotlin.Any operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
BLOCK type=kotlin.Unit operator=null
|
||||
CALL .<set-x> type=kotlin.Unit operator=EQ
|
||||
$this: THIS public final class TestInitVarWithCustomSetterWithExplicitCtor type=TestInitVarWithCustomSetterWithExplicitCtor
|
||||
value: CONST Int type=kotlin.Int value='0'
|
||||
CLASS CLASS TestInitVarWithCustomSetterInCtor
|
||||
PROPERTY public final var x: kotlin.Int getter=null setter=<set-x>
|
||||
PROPERTY_SETTER public final fun <set-x>(/*0*/ value: kotlin.Int): kotlin.Unit property=x
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=EQ
|
||||
GET_VAR value type=kotlin.Int operator=null
|
||||
FUN public constructor TestInitVarWithCustomSetterInCtor()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=kotlin.Any operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
CALL .<set-x> type=kotlin.Unit operator=EQ
|
||||
$this: THIS public final class TestInitVarWithCustomSetterInCtor type=TestInitVarWithCustomSetterInCtor
|
||||
value: CONST Int type=kotlin.Int value='42'
|
||||
+11
-6
@@ -2,8 +2,10 @@ FILE /primaryConstructor.kt
|
||||
CLASS CLASS Test1
|
||||
FUN public constructor Test1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
INITIALIZE_PROPERTY x
|
||||
INITIALIZE_PROPERTY y
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
SET_BACKING_FIELD y type=kotlin.Unit operator=null
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
PROPERTY public final val x: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
@@ -13,8 +15,10 @@ FILE /primaryConstructor.kt
|
||||
CLASS CLASS Test2
|
||||
FUN public constructor Test2(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
INITIALIZE_PROPERTY y
|
||||
INITIALIZE_PROPERTY x
|
||||
SET_BACKING_FIELD y type=kotlin.Unit operator=null
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=null
|
||||
PROPERTY public final val y: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
@@ -24,9 +28,10 @@ FILE /primaryConstructor.kt
|
||||
CLASS CLASS Test3
|
||||
FUN public constructor Test3(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
INITIALIZE_PROPERTY y
|
||||
SET_BACKING_FIELD y type=kotlin.Unit operator=null
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
BLOCK type=kotlin.Unit operator=null
|
||||
INITIALIZE_PROPERTY x
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=null
|
||||
PROPERTY public final val y: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
open class Base
|
||||
|
||||
class TestImplicitPrimaryConstructor : Base()
|
||||
|
||||
class TestExplicitPrimaryConstructor() : Base()
|
||||
|
||||
class TestWithDelegatingConstructor(val x: Int, val y: Int) : Base() {
|
||||
constructor(x: Int) : this(x, 0)
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
FILE /primaryConstructorWithSuperConstructorCall.kt
|
||||
CLASS CLASS Base
|
||||
FUN public constructor Base()
|
||||
BLOCK_BODY
|
||||
CLASS CLASS TestImplicitPrimaryConstructor
|
||||
FUN public constructor TestImplicitPrimaryConstructor()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
|
||||
CLASS CLASS TestExplicitPrimaryConstructor
|
||||
FUN public constructor TestExplicitPrimaryConstructor()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
|
||||
CLASS CLASS TestWithDelegatingConstructor
|
||||
FUN public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
SET_BACKING_FIELD y type=kotlin.Unit operator=null
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
PROPERTY public final val x: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
PROPERTY public final val y: kotlin.Int getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int)
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=TestWithDelegatingConstructor operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
x: GET_VAR x type=kotlin.Int operator=null
|
||||
y: CONST Int type=kotlin.Int value='0'
|
||||
@@ -0,0 +1,19 @@
|
||||
interface ILeft {
|
||||
fun foo() {}
|
||||
val bar: Int get() = 1
|
||||
}
|
||||
|
||||
interface IRight {
|
||||
fun foo() {}
|
||||
val bar: Int get() = 2
|
||||
}
|
||||
|
||||
class CBoth : ILeft, IRight {
|
||||
override fun foo() {
|
||||
super<ILeft>.foo()
|
||||
super<IRight>.foo()
|
||||
}
|
||||
|
||||
override val bar: Int
|
||||
get() = super<ILeft>.bar + super<IRight>.bar
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
FILE /qualifiedSuperCalls.kt
|
||||
CLASS INTERFACE ILeft
|
||||
FUN public open fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
PROPERTY public open val bar: kotlin.Int getter=<get-bar> setter=null
|
||||
PROPERTY_GETTER public open fun <get-bar>(): kotlin.Int property=bar
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from=<get-bar>
|
||||
CONST Int type=kotlin.Int value='1'
|
||||
CLASS INTERFACE IRight
|
||||
FUN public open fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
PROPERTY public open val bar: kotlin.Int getter=<get-bar> setter=null
|
||||
PROPERTY_GETTER public open fun <get-bar>(): kotlin.Int property=bar
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from=<get-bar>
|
||||
CONST Int type=kotlin.Int value='2'
|
||||
CLASS CLASS CBoth
|
||||
FUN public constructor CBoth()
|
||||
BLOCK_BODY
|
||||
FUN public open override /*2*/ fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL .foo superQualifier=ILeft type=kotlin.Unit operator=null
|
||||
$this: THIS public final class CBoth : ILeft, IRight type=ILeft
|
||||
CALL .foo superQualifier=IRight type=kotlin.Unit operator=null
|
||||
$this: THIS public final class CBoth : ILeft, IRight type=IRight
|
||||
PROPERTY public open override /*2*/ val bar: kotlin.Int getter=<get-bar> setter=null
|
||||
PROPERTY_GETTER public open override /*2*/ fun <get-bar>(): kotlin.Int property=bar
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from=<get-bar>
|
||||
CALL .plus type=kotlin.Int operator=PLUS
|
||||
$this: CALL .<get-bar> superQualifier=ILeft type=kotlin.Int operator=GET_PROPERTY
|
||||
$this: THIS public final class CBoth : ILeft, IRight type=ILeft
|
||||
other: CALL .<get-bar> superQualifier=IRight type=kotlin.Int operator=GET_PROPERTY
|
||||
$this: THIS public final class CBoth : ILeft, IRight type=IRight
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
open class Base
|
||||
|
||||
class TestProperty : Base {
|
||||
val x = 0
|
||||
constructor()
|
||||
}
|
||||
|
||||
class TestInitBlock : Base {
|
||||
val x: Int
|
||||
init {
|
||||
x = 0
|
||||
}
|
||||
constructor()
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
FILE /secondaryConstructorWithInitializersFromClassBody.kt
|
||||
CLASS CLASS Base
|
||||
FUN public constructor Base()
|
||||
BLOCK_BODY
|
||||
CLASS CLASS TestProperty
|
||||
PROPERTY public final val x: kotlin.Int = 0 getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
FUN public constructor TestProperty()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
CLASS CLASS TestInitBlock
|
||||
PROPERTY public final val x: kotlin.Int getter=null setter=null
|
||||
FUN public constructor TestInitBlock()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
|
||||
BLOCK type=kotlin.Unit operator=null
|
||||
SET_BACKING_FIELD x type=kotlin.Unit operator=null
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
@@ -0,0 +1,14 @@
|
||||
open class Base {
|
||||
open fun foo() {}
|
||||
|
||||
open val bar: String = ""
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
override fun foo() {
|
||||
super.foo()
|
||||
}
|
||||
|
||||
override val bar: String
|
||||
get() = super.bar
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
FILE /superCalls.kt
|
||||
CLASS CLASS Base
|
||||
FUN public constructor Base()
|
||||
BLOCK_BODY
|
||||
SET_BACKING_FIELD bar type=kotlin.Unit operator=null
|
||||
CONST String type=kotlin.String value=''
|
||||
FUN public open fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
PROPERTY public open val bar: kotlin.String = "" getter=null setter=null
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value=''
|
||||
CLASS CLASS Derived
|
||||
FUN public constructor Derived()
|
||||
BLOCK_BODY
|
||||
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
|
||||
FUN public open override /*1*/ fun foo(): kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL .foo superQualifier=Base type=kotlin.Unit operator=null
|
||||
$this: THIS public final class Derived : Base type=Base
|
||||
PROPERTY public open override /*1*/ val bar: kotlin.String getter=<get-bar> setter=null
|
||||
PROPERTY_GETTER public open override /*1*/ fun <get-bar>(): kotlin.String property=bar
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from=<get-bar>
|
||||
CALL .<get-bar> superQualifier=Base type=kotlin.String operator=GET_PROPERTY
|
||||
$this: THIS public final class Derived : Base type=Base
|
||||
Reference in New Issue
Block a user