[K/N][Tests] Move codegen test sources interfaceCallsNCasts..vector
^KT-61259
This commit is contained in:
committed by
Space Team
parent
56e1c5cbc6
commit
93642020ff
+686
@@ -0,0 +1,686 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.conservativeItable
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I0 {
|
||||
fun foo0(x: Int): Int
|
||||
}
|
||||
interface I1 {
|
||||
fun foo1(x: Int): Int
|
||||
}
|
||||
interface I2 {
|
||||
fun foo2(x: Int): Int
|
||||
}
|
||||
interface I3 {
|
||||
fun foo3(x: Int): Int
|
||||
}
|
||||
interface I4 {
|
||||
fun foo4(x: Int): Int
|
||||
}
|
||||
interface I5 {
|
||||
fun foo5(x: Int): Int
|
||||
}
|
||||
interface I6 {
|
||||
fun foo6(x: Int): Int
|
||||
}
|
||||
interface I7 {
|
||||
fun foo7(x: Int): Int
|
||||
}
|
||||
interface I8 {
|
||||
fun foo8(x: Int): Int
|
||||
}
|
||||
interface I9 {
|
||||
fun foo9(x: Int): Int
|
||||
}
|
||||
interface I10 {
|
||||
fun foo10(x: Int): Int
|
||||
}
|
||||
interface I11 {
|
||||
fun foo11(x: Int): Int
|
||||
}
|
||||
interface I12 {
|
||||
fun foo12(x: Int): Int
|
||||
}
|
||||
interface I13 {
|
||||
fun foo13(x: Int): Int
|
||||
}
|
||||
interface I14 {
|
||||
fun foo14(x: Int): Int
|
||||
}
|
||||
interface I15 {
|
||||
fun foo15(x: Int): Int
|
||||
}
|
||||
interface I16 {
|
||||
fun foo16(x: Int): Int
|
||||
}
|
||||
interface I17 {
|
||||
fun foo17(x: Int): Int
|
||||
}
|
||||
interface I18 {
|
||||
fun foo18(x: Int): Int
|
||||
}
|
||||
interface I19 {
|
||||
fun foo19(x: Int): Int
|
||||
}
|
||||
interface I20 {
|
||||
fun foo20(x: Int): Int
|
||||
}
|
||||
interface I21 {
|
||||
fun foo21(x: Int): Int
|
||||
}
|
||||
interface I22 {
|
||||
fun foo22(x: Int): Int
|
||||
}
|
||||
interface I23 {
|
||||
fun foo23(x: Int): Int
|
||||
}
|
||||
interface I24 {
|
||||
fun foo24(x: Int): Int
|
||||
}
|
||||
interface I25 {
|
||||
fun foo25(x: Int): Int
|
||||
}
|
||||
interface I26 {
|
||||
fun foo26(x: Int): Int
|
||||
}
|
||||
interface I27 {
|
||||
fun foo27(x: Int): Int
|
||||
}
|
||||
interface I28 {
|
||||
fun foo28(x: Int): Int
|
||||
}
|
||||
interface I29 {
|
||||
fun foo29(x: Int): Int
|
||||
}
|
||||
interface I30 {
|
||||
fun foo30(x: Int): Int
|
||||
}
|
||||
interface I31 {
|
||||
fun foo31(x: Int): Int
|
||||
}
|
||||
interface I32 {
|
||||
fun foo32(x: Int): Int
|
||||
}
|
||||
interface I33 {
|
||||
fun foo33(x: Int): Int
|
||||
}
|
||||
interface I34 {
|
||||
fun foo34(x: Int): Int
|
||||
}
|
||||
interface I35 {
|
||||
fun foo35(x: Int): Int
|
||||
}
|
||||
interface I36 {
|
||||
fun foo36(x: Int): Int
|
||||
}
|
||||
interface I37 {
|
||||
fun foo37(x: Int): Int
|
||||
}
|
||||
interface I38 {
|
||||
fun foo38(x: Int): Int
|
||||
}
|
||||
interface I39 {
|
||||
fun foo39(x: Int): Int
|
||||
}
|
||||
interface I40 {
|
||||
fun foo40(x: Int): Int
|
||||
}
|
||||
interface I41 {
|
||||
fun foo41(x: Int): Int
|
||||
}
|
||||
interface I42 {
|
||||
fun foo42(x: Int): Int
|
||||
}
|
||||
interface I43 {
|
||||
fun foo43(x: Int): Int
|
||||
}
|
||||
interface I44 {
|
||||
fun foo44(x: Int): Int
|
||||
}
|
||||
interface I45 {
|
||||
fun foo45(x: Int): Int
|
||||
}
|
||||
interface I46 {
|
||||
fun foo46(x: Int): Int
|
||||
}
|
||||
interface I47 {
|
||||
fun foo47(x: Int): Int
|
||||
}
|
||||
interface I48 {
|
||||
fun foo48(x: Int): Int
|
||||
}
|
||||
interface I49 {
|
||||
fun foo49(x: Int): Int
|
||||
}
|
||||
interface I50 {
|
||||
fun foo50(x: Int): Int
|
||||
}
|
||||
interface I51 {
|
||||
fun foo51(x: Int): Int
|
||||
}
|
||||
interface I52 {
|
||||
fun foo52(x: Int): Int
|
||||
}
|
||||
interface I53 {
|
||||
fun foo53(x: Int): Int
|
||||
}
|
||||
interface I54 {
|
||||
fun foo54(x: Int): Int
|
||||
}
|
||||
interface I55 {
|
||||
fun foo55(x: Int): Int
|
||||
}
|
||||
interface I56 {
|
||||
fun foo56(x: Int): Int
|
||||
}
|
||||
interface I57 {
|
||||
fun foo57(x: Int): Int
|
||||
}
|
||||
interface I58 {
|
||||
fun foo58(x: Int): Int
|
||||
}
|
||||
interface I59 {
|
||||
fun foo59(x: Int): Int
|
||||
}
|
||||
interface I60 {
|
||||
fun foo60(x: Int): Int
|
||||
}
|
||||
interface I61 {
|
||||
fun foo61(x: Int): Int
|
||||
}
|
||||
interface I62 {
|
||||
fun foo62(x: Int): Int
|
||||
}
|
||||
interface I63 {
|
||||
fun foo63(x: Int): Int
|
||||
}
|
||||
interface I64 {
|
||||
fun foo64(x: Int): Int
|
||||
}
|
||||
interface I65 {
|
||||
fun foo65(x: Int): Int
|
||||
}
|
||||
interface I66 {
|
||||
fun foo66(x: Int): Int
|
||||
}
|
||||
interface I67 {
|
||||
fun foo67(x: Int): Int
|
||||
}
|
||||
interface I68 {
|
||||
fun foo68(x: Int): Int
|
||||
}
|
||||
interface I69 {
|
||||
fun foo69(x: Int): Int
|
||||
}
|
||||
interface I70 {
|
||||
fun foo70(x: Int): Int
|
||||
}
|
||||
interface I71 {
|
||||
fun foo71(x: Int): Int
|
||||
}
|
||||
interface I72 {
|
||||
fun foo72(x: Int): Int
|
||||
}
|
||||
interface I73 {
|
||||
fun foo73(x: Int): Int
|
||||
}
|
||||
interface I74 {
|
||||
fun foo74(x: Int): Int
|
||||
}
|
||||
interface I75 {
|
||||
fun foo75(x: Int): Int
|
||||
}
|
||||
interface I76 {
|
||||
fun foo76(x: Int): Int
|
||||
}
|
||||
interface I77 {
|
||||
fun foo77(x: Int): Int
|
||||
}
|
||||
interface I78 {
|
||||
fun foo78(x: Int): Int
|
||||
}
|
||||
interface I79 {
|
||||
fun foo79(x: Int): Int
|
||||
}
|
||||
interface I80 {
|
||||
fun foo80(x: Int): Int
|
||||
}
|
||||
interface I81 {
|
||||
fun foo81(x: Int): Int
|
||||
}
|
||||
interface I82 {
|
||||
fun foo82(x: Int): Int
|
||||
}
|
||||
interface I83 {
|
||||
fun foo83(x: Int): Int
|
||||
}
|
||||
interface I84 {
|
||||
fun foo84(x: Int): Int
|
||||
}
|
||||
interface I85 {
|
||||
fun foo85(x: Int): Int
|
||||
}
|
||||
interface I86 {
|
||||
fun foo86(x: Int): Int
|
||||
}
|
||||
interface I87 {
|
||||
fun foo87(x: Int): Int
|
||||
}
|
||||
interface I88 {
|
||||
fun foo88(x: Int): Int
|
||||
}
|
||||
interface I89 {
|
||||
fun foo89(x: Int): Int
|
||||
}
|
||||
interface I90 {
|
||||
fun foo90(x: Int): Int
|
||||
}
|
||||
interface I91 {
|
||||
fun foo91(x: Int): Int
|
||||
}
|
||||
interface I92 {
|
||||
fun foo92(x: Int): Int
|
||||
}
|
||||
interface I93 {
|
||||
fun foo93(x: Int): Int
|
||||
}
|
||||
interface I94 {
|
||||
fun foo94(x: Int): Int
|
||||
}
|
||||
interface I95 {
|
||||
fun foo95(x: Int): Int
|
||||
}
|
||||
interface I96 {
|
||||
fun foo96(x: Int): Int
|
||||
}
|
||||
interface I97 {
|
||||
fun foo97(x: Int): Int
|
||||
}
|
||||
interface I98 {
|
||||
fun foo98(x: Int): Int
|
||||
}
|
||||
interface I99 {
|
||||
fun foo99(x: Int): Int
|
||||
}
|
||||
class Bar : I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19, I20, I21, I22,
|
||||
I23, I24, I25, I26, I27, I28, I29, I30, I31, I32, I33, I34, I35, I36, I37, I38, I39, I40, I41, I42, I43, I44,
|
||||
I45, I46, I47, I48, I49, I50, I51, I52, I53, I54, I55, I56, I57, I58, I59, I60, I61, I62, I63, I64, I65, I66,
|
||||
I67, I68, I69, I70, I71, I72, I73, I74, I75, I76, I77, I78, I79, I80, I81, I82, I83, I84, I85, I86, I87, I88,
|
||||
I89, I90, I91, I92, I93, I94, I95, I96, I97, I98, I99 {
|
||||
override fun foo0(x: Int) = x + 0
|
||||
override fun foo1(x: Int) = x + 1
|
||||
override fun foo2(x: Int) = x + 2
|
||||
override fun foo3(x: Int) = x + 3
|
||||
override fun foo4(x: Int) = x + 4
|
||||
override fun foo5(x: Int) = x + 5
|
||||
override fun foo6(x: Int) = x + 6
|
||||
override fun foo7(x: Int) = x + 7
|
||||
override fun foo8(x: Int) = x + 8
|
||||
override fun foo9(x: Int) = x + 9
|
||||
override fun foo10(x: Int) = x + 10
|
||||
override fun foo11(x: Int) = x + 11
|
||||
override fun foo12(x: Int) = x + 12
|
||||
override fun foo13(x: Int) = x + 13
|
||||
override fun foo14(x: Int) = x + 14
|
||||
override fun foo15(x: Int) = x + 15
|
||||
override fun foo16(x: Int) = x + 16
|
||||
override fun foo17(x: Int) = x + 17
|
||||
override fun foo18(x: Int) = x + 18
|
||||
override fun foo19(x: Int) = x + 19
|
||||
override fun foo20(x: Int) = x + 20
|
||||
override fun foo21(x: Int) = x + 21
|
||||
override fun foo22(x: Int) = x + 22
|
||||
override fun foo23(x: Int) = x + 23
|
||||
override fun foo24(x: Int) = x + 24
|
||||
override fun foo25(x: Int) = x + 25
|
||||
override fun foo26(x: Int) = x + 26
|
||||
override fun foo27(x: Int) = x + 27
|
||||
override fun foo28(x: Int) = x + 28
|
||||
override fun foo29(x: Int) = x + 29
|
||||
override fun foo30(x: Int) = x + 30
|
||||
override fun foo31(x: Int) = x + 31
|
||||
override fun foo32(x: Int) = x + 32
|
||||
override fun foo33(x: Int) = x + 33
|
||||
override fun foo34(x: Int) = x + 34
|
||||
override fun foo35(x: Int) = x + 35
|
||||
override fun foo36(x: Int) = x + 36
|
||||
override fun foo37(x: Int) = x + 37
|
||||
override fun foo38(x: Int) = x + 38
|
||||
override fun foo39(x: Int) = x + 39
|
||||
override fun foo40(x: Int) = x + 40
|
||||
override fun foo41(x: Int) = x + 41
|
||||
override fun foo42(x: Int) = x + 42
|
||||
override fun foo43(x: Int) = x + 43
|
||||
override fun foo44(x: Int) = x + 44
|
||||
override fun foo45(x: Int) = x + 45
|
||||
override fun foo46(x: Int) = x + 46
|
||||
override fun foo47(x: Int) = x + 47
|
||||
override fun foo48(x: Int) = x + 48
|
||||
override fun foo49(x: Int) = x + 49
|
||||
override fun foo50(x: Int) = x + 50
|
||||
override fun foo51(x: Int) = x + 51
|
||||
override fun foo52(x: Int) = x + 52
|
||||
override fun foo53(x: Int) = x + 53
|
||||
override fun foo54(x: Int) = x + 54
|
||||
override fun foo55(x: Int) = x + 55
|
||||
override fun foo56(x: Int) = x + 56
|
||||
override fun foo57(x: Int) = x + 57
|
||||
override fun foo58(x: Int) = x + 58
|
||||
override fun foo59(x: Int) = x + 59
|
||||
override fun foo60(x: Int) = x + 60
|
||||
override fun foo61(x: Int) = x + 61
|
||||
override fun foo62(x: Int) = x + 62
|
||||
override fun foo63(x: Int) = x + 63
|
||||
override fun foo64(x: Int) = x + 64
|
||||
override fun foo65(x: Int) = x + 65
|
||||
override fun foo66(x: Int) = x + 66
|
||||
override fun foo67(x: Int) = x + 67
|
||||
override fun foo68(x: Int) = x + 68
|
||||
override fun foo69(x: Int) = x + 69
|
||||
override fun foo70(x: Int) = x + 70
|
||||
override fun foo71(x: Int) = x + 71
|
||||
override fun foo72(x: Int) = x + 72
|
||||
override fun foo73(x: Int) = x + 73
|
||||
override fun foo74(x: Int) = x + 74
|
||||
override fun foo75(x: Int) = x + 75
|
||||
override fun foo76(x: Int) = x + 76
|
||||
override fun foo77(x: Int) = x + 77
|
||||
override fun foo78(x: Int) = x + 78
|
||||
override fun foo79(x: Int) = x + 79
|
||||
override fun foo80(x: Int) = x + 80
|
||||
override fun foo81(x: Int) = x + 81
|
||||
override fun foo82(x: Int) = x + 82
|
||||
override fun foo83(x: Int) = x + 83
|
||||
override fun foo84(x: Int) = x + 84
|
||||
override fun foo85(x: Int) = x + 85
|
||||
override fun foo86(x: Int) = x + 86
|
||||
override fun foo87(x: Int) = x + 87
|
||||
override fun foo88(x: Int) = x + 88
|
||||
override fun foo89(x: Int) = x + 89
|
||||
override fun foo90(x: Int) = x + 90
|
||||
override fun foo91(x: Int) = x + 91
|
||||
override fun foo92(x: Int) = x + 92
|
||||
override fun foo93(x: Int) = x + 93
|
||||
override fun foo94(x: Int) = x + 94
|
||||
override fun foo95(x: Int) = x + 95
|
||||
override fun foo96(x: Int) = x + 96
|
||||
override fun foo97(x: Int) = x + 97
|
||||
override fun foo98(x: Int) = x + 98
|
||||
override fun foo99(x: Int) = x + 99
|
||||
}
|
||||
|
||||
fun check_is_I0(x: Any) = x is I0
|
||||
fun check_is_I1(x: Any) = x is I1
|
||||
fun check_is_I2(x: Any) = x is I2
|
||||
fun check_is_I3(x: Any) = x is I3
|
||||
fun check_is_I4(x: Any) = x is I4
|
||||
fun check_is_I5(x: Any) = x is I5
|
||||
fun check_is_I6(x: Any) = x is I6
|
||||
fun check_is_I7(x: Any) = x is I7
|
||||
fun check_is_I8(x: Any) = x is I8
|
||||
fun check_is_I9(x: Any) = x is I9
|
||||
fun check_is_I10(x: Any) = x is I10
|
||||
fun check_is_I11(x: Any) = x is I11
|
||||
fun check_is_I12(x: Any) = x is I12
|
||||
fun check_is_I13(x: Any) = x is I13
|
||||
fun check_is_I14(x: Any) = x is I14
|
||||
fun check_is_I15(x: Any) = x is I15
|
||||
fun check_is_I16(x: Any) = x is I16
|
||||
fun check_is_I17(x: Any) = x is I17
|
||||
fun check_is_I18(x: Any) = x is I18
|
||||
fun check_is_I19(x: Any) = x is I19
|
||||
fun check_is_I20(x: Any) = x is I20
|
||||
fun check_is_I21(x: Any) = x is I21
|
||||
fun check_is_I22(x: Any) = x is I22
|
||||
fun check_is_I23(x: Any) = x is I23
|
||||
fun check_is_I24(x: Any) = x is I24
|
||||
fun check_is_I25(x: Any) = x is I25
|
||||
fun check_is_I26(x: Any) = x is I26
|
||||
fun check_is_I27(x: Any) = x is I27
|
||||
fun check_is_I28(x: Any) = x is I28
|
||||
fun check_is_I29(x: Any) = x is I29
|
||||
fun check_is_I30(x: Any) = x is I30
|
||||
fun check_is_I31(x: Any) = x is I31
|
||||
fun check_is_I32(x: Any) = x is I32
|
||||
fun check_is_I33(x: Any) = x is I33
|
||||
fun check_is_I34(x: Any) = x is I34
|
||||
fun check_is_I35(x: Any) = x is I35
|
||||
fun check_is_I36(x: Any) = x is I36
|
||||
fun check_is_I37(x: Any) = x is I37
|
||||
fun check_is_I38(x: Any) = x is I38
|
||||
fun check_is_I39(x: Any) = x is I39
|
||||
fun check_is_I40(x: Any) = x is I40
|
||||
fun check_is_I41(x: Any) = x is I41
|
||||
fun check_is_I42(x: Any) = x is I42
|
||||
fun check_is_I43(x: Any) = x is I43
|
||||
fun check_is_I44(x: Any) = x is I44
|
||||
fun check_is_I45(x: Any) = x is I45
|
||||
fun check_is_I46(x: Any) = x is I46
|
||||
fun check_is_I47(x: Any) = x is I47
|
||||
fun check_is_I48(x: Any) = x is I48
|
||||
fun check_is_I49(x: Any) = x is I49
|
||||
fun check_is_I50(x: Any) = x is I50
|
||||
fun check_is_I51(x: Any) = x is I51
|
||||
fun check_is_I52(x: Any) = x is I52
|
||||
fun check_is_I53(x: Any) = x is I53
|
||||
fun check_is_I54(x: Any) = x is I54
|
||||
fun check_is_I55(x: Any) = x is I55
|
||||
fun check_is_I56(x: Any) = x is I56
|
||||
fun check_is_I57(x: Any) = x is I57
|
||||
fun check_is_I58(x: Any) = x is I58
|
||||
fun check_is_I59(x: Any) = x is I59
|
||||
fun check_is_I60(x: Any) = x is I60
|
||||
fun check_is_I61(x: Any) = x is I61
|
||||
fun check_is_I62(x: Any) = x is I62
|
||||
fun check_is_I63(x: Any) = x is I63
|
||||
fun check_is_I64(x: Any) = x is I64
|
||||
fun check_is_I65(x: Any) = x is I65
|
||||
fun check_is_I66(x: Any) = x is I66
|
||||
fun check_is_I67(x: Any) = x is I67
|
||||
fun check_is_I68(x: Any) = x is I68
|
||||
fun check_is_I69(x: Any) = x is I69
|
||||
fun check_is_I70(x: Any) = x is I70
|
||||
fun check_is_I71(x: Any) = x is I71
|
||||
fun check_is_I72(x: Any) = x is I72
|
||||
fun check_is_I73(x: Any) = x is I73
|
||||
fun check_is_I74(x: Any) = x is I74
|
||||
fun check_is_I75(x: Any) = x is I75
|
||||
fun check_is_I76(x: Any) = x is I76
|
||||
fun check_is_I77(x: Any) = x is I77
|
||||
fun check_is_I78(x: Any) = x is I78
|
||||
fun check_is_I79(x: Any) = x is I79
|
||||
fun check_is_I80(x: Any) = x is I80
|
||||
fun check_is_I81(x: Any) = x is I81
|
||||
fun check_is_I82(x: Any) = x is I82
|
||||
fun check_is_I83(x: Any) = x is I83
|
||||
fun check_is_I84(x: Any) = x is I84
|
||||
fun check_is_I85(x: Any) = x is I85
|
||||
fun check_is_I86(x: Any) = x is I86
|
||||
fun check_is_I87(x: Any) = x is I87
|
||||
fun check_is_I88(x: Any) = x is I88
|
||||
fun check_is_I89(x: Any) = x is I89
|
||||
fun check_is_I90(x: Any) = x is I90
|
||||
fun check_is_I91(x: Any) = x is I91
|
||||
fun check_is_I92(x: Any) = x is I92
|
||||
fun check_is_I93(x: Any) = x is I93
|
||||
fun check_is_I94(x: Any) = x is I94
|
||||
fun check_is_I95(x: Any) = x is I95
|
||||
fun check_is_I96(x: Any) = x is I96
|
||||
fun check_is_I97(x: Any) = x is I97
|
||||
fun check_is_I98(x: Any) = x is I98
|
||||
fun check_is_I99(x: Any) = x is I99
|
||||
|
||||
interface I_M1 {
|
||||
fun bar(x: Int): Int
|
||||
}
|
||||
|
||||
class Bar2 : I_M1 {
|
||||
override fun bar(x: Int) = 497 * x + 42
|
||||
}
|
||||
|
||||
class I42_Impl1 : I42 {
|
||||
override fun foo42(x: Int) = x * 2 + 42
|
||||
}
|
||||
|
||||
class I42_Impl2 : I42 {
|
||||
override fun foo42(x: Int) = x * 3 + 42
|
||||
}
|
||||
|
||||
class I42_Impl3 : I42 {
|
||||
override fun foo42(x: Int) = x * 4 + 42
|
||||
}
|
||||
|
||||
class I42_Impl4 : I42 {
|
||||
override fun foo42(x: Int) = x * 5 + 42
|
||||
}
|
||||
|
||||
class I42_Impl5 : I42 {
|
||||
override fun foo42(x: Int) = x * 6 + 42
|
||||
}
|
||||
|
||||
class I42_Impl6 : I42 {
|
||||
override fun foo42(x: Int) = x * 7 + 42
|
||||
}
|
||||
|
||||
class I42_Impl7 : I42 {
|
||||
override fun foo42(x: Int) = x * 8 + 42
|
||||
}
|
||||
|
||||
class I42_Impl8 : I42 {
|
||||
override fun foo42(x: Int) = x * 9 + 42
|
||||
}
|
||||
|
||||
fun foo(i42: I42, x: Int) = i42.foo42(x)
|
||||
|
||||
fun bar(i_m1: I_M1, x: Int) = i_m1.bar(x)
|
||||
|
||||
@Test fun runTest() {
|
||||
val y = Bar2()
|
||||
println(bar(y, 1))
|
||||
val x0 = Bar()
|
||||
var t = 0
|
||||
if (check_is_I0(x0)) t = t + 1
|
||||
if (check_is_I1(x0)) t = t + 2
|
||||
if (check_is_I2(x0)) t = t + 3
|
||||
if (check_is_I3(x0)) t = t + 4
|
||||
if (check_is_I4(x0)) t = t + 5
|
||||
if (check_is_I5(x0)) t = t + 6
|
||||
if (check_is_I6(x0)) t = t + 7
|
||||
if (check_is_I7(x0)) t = t + 8
|
||||
if (check_is_I8(x0)) t = t + 9
|
||||
if (check_is_I9(x0)) t = t + 10
|
||||
if (check_is_I10(x0)) t = t + 11
|
||||
if (check_is_I11(x0)) t = t + 12
|
||||
if (check_is_I12(x0)) t = t + 13
|
||||
if (check_is_I13(x0)) t = t + 14
|
||||
if (check_is_I14(x0)) t = t + 15
|
||||
if (check_is_I15(x0)) t = t + 16
|
||||
if (check_is_I16(x0)) t = t + 17
|
||||
if (check_is_I17(x0)) t = t + 18
|
||||
if (check_is_I18(x0)) t = t + 19
|
||||
if (check_is_I19(x0)) t = t + 20
|
||||
if (check_is_I20(x0)) t = t + 21
|
||||
if (check_is_I21(x0)) t = t + 22
|
||||
if (check_is_I22(x0)) t = t + 23
|
||||
if (check_is_I23(x0)) t = t + 24
|
||||
if (check_is_I24(x0)) t = t + 25
|
||||
if (check_is_I25(x0)) t = t + 26
|
||||
if (check_is_I26(x0)) t = t + 27
|
||||
if (check_is_I27(x0)) t = t + 28
|
||||
if (check_is_I28(x0)) t = t + 29
|
||||
if (check_is_I29(x0)) t = t + 30
|
||||
if (check_is_I30(x0)) t = t + 31
|
||||
if (check_is_I31(x0)) t = t + 32
|
||||
if (check_is_I32(x0)) t = t + 33
|
||||
if (check_is_I33(x0)) t = t + 34
|
||||
if (check_is_I34(x0)) t = t + 35
|
||||
if (check_is_I35(x0)) t = t + 36
|
||||
if (check_is_I36(x0)) t = t + 37
|
||||
if (check_is_I37(x0)) t = t + 38
|
||||
if (check_is_I38(x0)) t = t + 39
|
||||
if (check_is_I39(x0)) t = t + 40
|
||||
if (check_is_I40(x0)) t = t + 41
|
||||
if (check_is_I41(x0)) t = t + 42
|
||||
if (check_is_I42(x0)) t = t + 43
|
||||
if (check_is_I43(x0)) t = t + 44
|
||||
if (check_is_I44(x0)) t = t + 45
|
||||
if (check_is_I45(x0)) t = t + 46
|
||||
if (check_is_I46(x0)) t = t + 47
|
||||
if (check_is_I47(x0)) t = t + 48
|
||||
if (check_is_I48(x0)) t = t + 49
|
||||
if (check_is_I49(x0)) t = t + 50
|
||||
if (check_is_I50(x0)) t = t + 51
|
||||
if (check_is_I51(x0)) t = t + 52
|
||||
if (check_is_I52(x0)) t = t + 53
|
||||
if (check_is_I53(x0)) t = t + 54
|
||||
if (check_is_I54(x0)) t = t + 55
|
||||
if (check_is_I55(x0)) t = t + 56
|
||||
if (check_is_I56(x0)) t = t + 57
|
||||
if (check_is_I57(x0)) t = t + 58
|
||||
if (check_is_I58(x0)) t = t + 59
|
||||
if (check_is_I59(x0)) t = t + 60
|
||||
if (check_is_I60(x0)) t = t + 61
|
||||
if (check_is_I61(x0)) t = t + 62
|
||||
if (check_is_I62(x0)) t = t + 63
|
||||
if (check_is_I63(x0)) t = t + 64
|
||||
if (check_is_I64(x0)) t = t + 65
|
||||
if (check_is_I65(x0)) t = t + 66
|
||||
if (check_is_I66(x0)) t = t + 67
|
||||
if (check_is_I67(x0)) t = t + 68
|
||||
if (check_is_I68(x0)) t = t + 69
|
||||
if (check_is_I69(x0)) t = t + 70
|
||||
if (check_is_I70(x0)) t = t + 71
|
||||
if (check_is_I71(x0)) t = t + 72
|
||||
if (check_is_I72(x0)) t = t + 73
|
||||
if (check_is_I73(x0)) t = t + 74
|
||||
if (check_is_I74(x0)) t = t + 75
|
||||
if (check_is_I75(x0)) t = t + 76
|
||||
if (check_is_I76(x0)) t = t + 77
|
||||
if (check_is_I77(x0)) t = t + 78
|
||||
if (check_is_I78(x0)) t = t + 79
|
||||
if (check_is_I79(x0)) t = t + 80
|
||||
if (check_is_I80(x0)) t = t + 81
|
||||
if (check_is_I81(x0)) t = t + 82
|
||||
if (check_is_I82(x0)) t = t + 83
|
||||
if (check_is_I83(x0)) t = t + 84
|
||||
if (check_is_I84(x0)) t = t + 85
|
||||
if (check_is_I85(x0)) t = t + 86
|
||||
if (check_is_I86(x0)) t = t + 87
|
||||
if (check_is_I87(x0)) t = t + 88
|
||||
if (check_is_I88(x0)) t = t + 89
|
||||
if (check_is_I89(x0)) t = t + 90
|
||||
if (check_is_I90(x0)) t = t + 91
|
||||
if (check_is_I91(x0)) t = t + 92
|
||||
if (check_is_I92(x0)) t = t + 93
|
||||
if (check_is_I93(x0)) t = t + 94
|
||||
if (check_is_I94(x0)) t = t + 95
|
||||
if (check_is_I95(x0)) t = t + 96
|
||||
if (check_is_I96(x0)) t = t + 97
|
||||
if (check_is_I97(x0)) t = t + 98
|
||||
if (check_is_I98(x0)) t = t + 99
|
||||
if (check_is_I99(x0)) t = t + 100
|
||||
println(t)
|
||||
val x1 = I42_Impl1()
|
||||
val x2 = I42_Impl2()
|
||||
val x3 = I42_Impl3()
|
||||
val x4 = I42_Impl4()
|
||||
val x5 = I42_Impl5()
|
||||
val x6 = I42_Impl6()
|
||||
val x7 = I42_Impl7()
|
||||
val x8 = I42_Impl8()
|
||||
t = foo(x0, 1)
|
||||
t = foo(x1, t)
|
||||
t = foo(x2, t)
|
||||
t = foo(x3, t)
|
||||
t = foo(x4, t)
|
||||
t = foo(x5, t)
|
||||
t = foo(x6, t)
|
||||
t = foo(x7, t)
|
||||
t = foo(x8, t)
|
||||
println(t)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
539
|
||||
5050
|
||||
26551140
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.diamond
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A<T, U> {
|
||||
fun foo(t: T, u: U) = "A"
|
||||
}
|
||||
|
||||
interface B<U> : A<String, U>
|
||||
|
||||
interface C<T> : A<T, Int>
|
||||
|
||||
class Z : B<Int>, C<String> {
|
||||
override fun foo(t: String, u: Int) = "Z"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val z = Z()
|
||||
val c: C<String> = z
|
||||
val b: B<Int> = z
|
||||
val a: A<String, Int> = z
|
||||
|
||||
assertEquals("Z", z.foo("", 0))
|
||||
assertEquals("Z", c.foo("", 0))
|
||||
assertEquals("Z", b.foo("", 0))
|
||||
assertEquals("Z", a.foo("", 0))
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.finalMethod
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I1<T> {
|
||||
fun defaultX(): T
|
||||
fun foo(x: T = defaultX()): T
|
||||
}
|
||||
|
||||
interface I2 : I1<Int> {
|
||||
|
||||
}
|
||||
|
||||
class C : I2 {
|
||||
override fun defaultX() = 42
|
||||
override fun foo(x: Int) = x
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val c: I2 = C()
|
||||
assertEquals(42, c.foo())
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.functionNameClash
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I1<T> {
|
||||
fun foo(x: T): String
|
||||
}
|
||||
interface I2<T> {
|
||||
fun foo(x: T): String
|
||||
}
|
||||
class C : I1<String>, I2<Int> {
|
||||
override fun foo(x: String) = "I1.foo($x)"
|
||||
override fun foo(x: Int) = "I2.foo($x)"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val c = C()
|
||||
val i1: I1<String> = c
|
||||
assertEquals("I1.foo(str)", i1.foo("str"))
|
||||
val i2: I2<Int> = c
|
||||
assertEquals("I2.foo(42)", i2.foo(42))
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
|
||||
@file:OptIn(ExperimentalForeignApi::class)
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun box(): String {
|
||||
val values = mutableListOf<Long>()
|
||||
for (value in listOf(
|
||||
0L,
|
||||
Byte.MIN_VALUE.toLong(), Byte.MAX_VALUE.toLong(), UByte.MAX_VALUE.toLong(),
|
||||
Short.MIN_VALUE.toLong(), Short.MAX_VALUE.toLong(), UShort.MAX_VALUE.toLong(),
|
||||
Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong(), UInt.MAX_VALUE.toLong(),
|
||||
Long.MIN_VALUE.toLong(), Long.MAX_VALUE.toLong(), ULong.MAX_VALUE.toLong()
|
||||
)) {
|
||||
values.add(value - 1)
|
||||
values.add(value)
|
||||
values.add(value + 1)
|
||||
}
|
||||
|
||||
for (value in values) {
|
||||
testConvertAll(value.toByte())
|
||||
testConvertAll(value.toUByte())
|
||||
testConvertAll(value.toShort())
|
||||
testConvertAll(value.toUShort())
|
||||
testConvertAll(value.toInt())
|
||||
testConvertAll(value.toUInt())
|
||||
testConvertAll(value.toLong())
|
||||
testConvertAll(value.toULong())
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun testConvertAll(value: Byte) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
|
||||
assertEquals(value.toByte(), value.narrow<Byte>())
|
||||
|
||||
assertEquals(value.toByte(), value.signExtend<Byte>())
|
||||
assertEquals(value.toShort(), value.signExtend<Short>())
|
||||
assertEquals(value.toInt(), value.signExtend<Int>())
|
||||
assertEquals(value.toLong(), value.signExtend<Long>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: Short) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
|
||||
assertEquals(value.toByte(), value.narrow<Byte>())
|
||||
assertEquals(value.toShort(), value.narrow<Short>())
|
||||
|
||||
assertEquals(value.toShort(), value.signExtend<Short>())
|
||||
assertEquals(value.toInt(), value.signExtend<Int>())
|
||||
assertEquals(value.toLong(), value.signExtend<Long>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: Int) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
|
||||
assertEquals(value.toByte(), value.narrow<Byte>())
|
||||
assertEquals(value.toShort(), value.narrow<Short>())
|
||||
assertEquals(value.toInt(), value.narrow<Int>())
|
||||
|
||||
assertEquals(value.toInt(), value.signExtend<Int>())
|
||||
assertEquals(value.toLong(), value.signExtend<Long>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: Long) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
|
||||
assertEquals(value.toByte(), value.narrow<Byte>())
|
||||
assertEquals(value.toShort(), value.narrow<Short>())
|
||||
assertEquals(value.toInt(), value.narrow<Int>())
|
||||
assertEquals(value.toLong(), value.narrow<Long>())
|
||||
|
||||
assertEquals(value.toLong(), value.signExtend<Long>())
|
||||
}
|
||||
|
||||
|
||||
fun testConvertAll(value: UByte) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: UShort) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: UInt) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
}
|
||||
|
||||
fun testConvertAll(value: ULong) {
|
||||
assertEquals(value.toByte(), value.convert<Byte>())
|
||||
assertEquals(value.toUByte(), value.convert<UByte>())
|
||||
assertEquals(value.toShort(), value.convert<Short>())
|
||||
assertEquals(value.toUShort(), value.convert<UShort>())
|
||||
assertEquals(value.toInt(), value.convert<Int>())
|
||||
assertEquals(value.toUInt(), value.convert<UInt>())
|
||||
assertEquals(value.toLong(), value.convert<Long>())
|
||||
assertEquals(value.toULong(), value.convert<ULong>())
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
@file:OptIn(ExperimentalForeignApi::class)
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun convertIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.convert() else null
|
||||
fun narrowIntToShortOrNull(i: Int, b: Boolean): Short? = if (b) i.narrow() else null
|
||||
fun signExtendShortToIntOrNull(i: Short, b: Boolean): Int? = if (b) i.signExtend() else null
|
||||
|
||||
fun box(): String {
|
||||
assertNull(convertIntToShortOrNull(0, false))
|
||||
assertEquals(1, convertIntToShortOrNull(1, true))
|
||||
|
||||
assertNull(narrowIntToShortOrNull(2, false))
|
||||
assertEquals(3, narrowIntToShortOrNull(3, true))
|
||||
|
||||
assertNull(signExtendShortToIntOrNull(4, false))
|
||||
assertEquals(5, signExtendShortToIntOrNull(5, true))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
@file:OptIn(ExperimentalForeignApi::class)
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, 257.convert<Byte>())
|
||||
assertEquals(255u, (-1).convert<UByte>())
|
||||
assertEquals(0, Long.MIN_VALUE.narrow<Int>())
|
||||
assertEquals(-1, Long.MAX_VALUE.narrow<Short>())
|
||||
assertEquals(-1L, (-1).signExtend<Long>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
|
||||
|
||||
package codegen.intrinsics.interop_sourceCodeStruct
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlinx.cinterop.internal.*
|
||||
import kotlin.test.*
|
||||
|
||||
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
|
||||
// Used by auto-generated code, user-defined structs should be declared via
|
||||
// structs in C headers or .def files instead.
|
||||
|
||||
@CStruct("struct { int p0; int p1; }")
|
||||
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
||||
|
||||
companion object : CStructVar.Type(8, 4)
|
||||
|
||||
var x: Int
|
||||
get() = memberAt<IntVar>(0).value
|
||||
set(value) {
|
||||
memberAt<IntVar>(0).value = value
|
||||
}
|
||||
|
||||
var y: Int
|
||||
get() = memberAt<IntVar>(4).value
|
||||
set(value) {
|
||||
memberAt<IntVar>(4).value = value
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test() = memScoped {
|
||||
val s = alloc<S>()
|
||||
|
||||
s.x = 123
|
||||
assertEquals(123, s.x)
|
||||
assertEquals(123, s.ptr.reinterpret<IntVar>()[0])
|
||||
|
||||
s.y = 321
|
||||
assertEquals(321, s.y)
|
||||
assertEquals(321, s.ptr.reinterpret<IntVar>()[1])
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@Test
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
fun testIsExperimentalMM() {
|
||||
if (isExperimentalMM()) {
|
||||
assertEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
|
||||
} else {
|
||||
assertNotEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.kclass.kClassEnumArgument
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
enum class E(val arg: KClass<*>?) {
|
||||
A(null as KClass<*>?),
|
||||
B(String::class);
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(E.B.arg?.simpleName)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
String
|
||||
@@ -0,0 +1,634 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.kclass.kclass0
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Test fun runTest() {
|
||||
main(emptyArray<String>())
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
checkBasics()
|
||||
checkLocalClasses(args)
|
||||
checkAnonymousObjects(args)
|
||||
checkAnonymousObjectsAssignedToProperty(args)
|
||||
checkFunctionReferences()
|
||||
checkInterfaces()
|
||||
checkEtc()
|
||||
}
|
||||
|
||||
private fun checkBasics() {
|
||||
checkClass(
|
||||
clazz = Any::class,
|
||||
expectedQualifiedName = "kotlin.Any",
|
||||
expectedSimpleName = "Any",
|
||||
expectedToStringName = "class kotlin.Any",
|
||||
expectedInstance = Any(),
|
||||
expectedNotInstance = null
|
||||
)
|
||||
checkClass(
|
||||
clazz = Int::class,
|
||||
expectedQualifiedName = "kotlin.Int",
|
||||
expectedSimpleName = "Int",
|
||||
expectedToStringName = "class kotlin.Int",
|
||||
expectedInstance = 42,
|
||||
expectedNotInstance = "17"
|
||||
)
|
||||
checkClass(
|
||||
clazz = String::class,
|
||||
expectedQualifiedName = "kotlin.String",
|
||||
expectedSimpleName = "String",
|
||||
expectedToStringName = "class kotlin.String",
|
||||
expectedInstance = "17",
|
||||
expectedNotInstance = 42
|
||||
)
|
||||
checkClass(
|
||||
clazz = TopLevel::class,
|
||||
expectedQualifiedName = "codegen.kclass.kclass0.TopLevel",
|
||||
expectedSimpleName = "TopLevel",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.TopLevel",
|
||||
expectedInstance = TopLevel(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = TopLevel.Nested::class,
|
||||
expectedQualifiedName = "codegen.kclass.kclass0.TopLevel.Nested",
|
||||
expectedSimpleName = "Nested",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.TopLevel.Nested",
|
||||
expectedInstance = TopLevel.Nested(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkLocalClasses(args: Array<String>) {
|
||||
// Local class.
|
||||
class Local0 {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local0::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local0",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$Local0",
|
||||
expectedInstance = Local0(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local0.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$Local0\$Inner",
|
||||
expectedInstance = Local0().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
|
||||
// Local class inside of lambda.
|
||||
;{
|
||||
class Local {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$1\$Local",
|
||||
expectedInstance = Local(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$1\$Local\$Inner",
|
||||
expectedInstance = Local().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}.invoke()
|
||||
|
||||
// Local class inside of non-inlined lambda.
|
||||
runNonInlining {
|
||||
class Local {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$2\$Local",
|
||||
expectedInstance = Local(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$2\$Local\$Inner",
|
||||
expectedInstance = Local().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
// Local class inside of inlined lambda.
|
||||
run {
|
||||
class Local {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$Local",
|
||||
expectedInstance = Local(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$Local\$Inner",
|
||||
expectedInstance = Local().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
// Local class inside of suspend lambda.
|
||||
suspend {
|
||||
class Local {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$3\$Local",
|
||||
expectedInstance = Local(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$3\$Local\$Inner",
|
||||
expectedInstance = Local().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}.runCoroutine()
|
||||
|
||||
// Local class inside of suspend function.
|
||||
suspend fun suspendFunWithLocalClass() {
|
||||
class Local {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
}
|
||||
checkClass(
|
||||
clazz = Local::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Local",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$suspendFunWithLocalClass\$Local",
|
||||
expectedInstance = Local(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Local.Inner::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkLocalClasses\$suspendFunWithLocalClass\$Local\$Inner",
|
||||
expectedInstance = Local().Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
::suspendFunWithLocalClass.runCoroutine()
|
||||
}
|
||||
|
||||
interface HasFoo {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
private inline fun getHasFoo(s: String) = object : HasFoo {
|
||||
override fun foo(): String = s
|
||||
}
|
||||
|
||||
private fun checkAnonymousObjects(args: Array<String>) {
|
||||
// Anonymous object.
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$1",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$1\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
// Anonymous object inside of lambda.
|
||||
;{
|
||||
// $2 goes for this lambda itself.
|
||||
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$2\$1",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$2\$1\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
}.invoke()
|
||||
|
||||
// Anonymous object inside of non-inlined lambda.
|
||||
runNonInlining {
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$3\$1",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$3\$1\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Anonymous object inside of inlined lambda.
|
||||
run {
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$4",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$4\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Anonymous object inside of suspend lambda.
|
||||
suspend {
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$5\$1",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$5\$1\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
}.runCoroutine()
|
||||
|
||||
// Anonymous object inside of suspend function.
|
||||
suspend fun suspendFunWithAnonymousObject() {
|
||||
// $1 goes for lambda created in `::suspendFunWithAnonymousObject.runCoroutine()` call.
|
||||
|
||||
with(object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}) {
|
||||
checkClass(
|
||||
clazz = this::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$suspendFunWithAnonymousObject\$2",
|
||||
expectedInstance = this,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = this.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjects\$suspendFunWithAnonymousObject\$2\$Inner",
|
||||
expectedInstance = this.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
}
|
||||
::suspendFunWithAnonymousObject.runCoroutine()
|
||||
|
||||
val hasFoo = getHasFoo("zzz")
|
||||
checkClass(
|
||||
hasFoo::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.Kclass0Kt$1",
|
||||
expectedInstance = hasFoo,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkAnonymousObjectsAssignedToProperty(args: Array<String>) {
|
||||
// Anonymous object.
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$1",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$1\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
|
||||
// Anonymous object inside of lambda.
|
||||
;{
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$2\$1",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$2\$1\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}.invoke()
|
||||
|
||||
// Anonymous object inside of non-inlined lambda.
|
||||
runNonInlining {
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$3\$1",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$3\$1\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
// Anonymous object inside of inlined lambda.
|
||||
run {
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$4",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$4\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
// Anonymous object inside of suspend lambda.
|
||||
suspend {
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$5\$1",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$5\$1\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}.runCoroutine()
|
||||
|
||||
// Anonymous object inside of suspend function.
|
||||
suspend fun suspendFunWithAnonymousObject() {
|
||||
// $1 goes for lambda created in `::suspendFunWithAnonymousObject.runCoroutine()` call.
|
||||
|
||||
val obj = object : Any() {
|
||||
val captured = args
|
||||
inner class Inner
|
||||
val innerKClass = Inner::class
|
||||
}
|
||||
checkClass(
|
||||
clazz = obj::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$suspendFunWithAnonymousObject\$2",
|
||||
expectedInstance = obj,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = obj.innerKClass,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = "Inner",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkAnonymousObjectsAssignedToProperty\$suspendFunWithAnonymousObject\$2\$Inner",
|
||||
expectedInstance = obj.Inner(),
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
::suspendFunWithAnonymousObject.runCoroutine()
|
||||
}
|
||||
|
||||
private fun checkFunctionReferences() {
|
||||
// TODO add tests for lambdas and anonymous functions, see KT-47194
|
||||
fun foo() = Unit
|
||||
val ref = ::foo
|
||||
checkClass(
|
||||
clazz = ref::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.checkFunctionReferences\$1",
|
||||
expectedInstance = ref,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkInterfaces() {
|
||||
checkClass(
|
||||
clazz = Comparable::class,
|
||||
expectedQualifiedName = "kotlin.Comparable",
|
||||
expectedSimpleName = "Comparable",
|
||||
expectedToStringName = "class kotlin.Comparable",
|
||||
expectedInstance = 42,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
checkClass(
|
||||
clazz = Interface::class,
|
||||
expectedQualifiedName = "codegen.kclass.kclass0.Interface",
|
||||
expectedSimpleName = "Interface",
|
||||
expectedToStringName = "class codegen.kclass.kclass0.Interface",
|
||||
expectedInstance = object : Interface {},
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkEtc() {
|
||||
checkInstanceClass(Any(), Any::class)
|
||||
checkInstanceClass(42, Int::class)
|
||||
assertEquals(42::class, Int::class)
|
||||
|
||||
class Local
|
||||
|
||||
checkReifiedClass<Int>(Int::class)
|
||||
checkReifiedClass<Int?>(Int::class)
|
||||
checkReifiedClass2<Int>(Int::class)
|
||||
checkReifiedClass2<Int?>(Int::class)
|
||||
checkReifiedClass<Any>(Any::class)
|
||||
checkReifiedClass2<Any>(Any::class)
|
||||
checkReifiedClass2<Any?>(Any::class)
|
||||
checkReifiedClass<Local>(Local::class)
|
||||
checkReifiedClass2<Local>(Local::class)
|
||||
checkReifiedClass<TopLevel>(TopLevel::class)
|
||||
checkReifiedClass2<TopLevel>(TopLevel::class)
|
||||
}
|
||||
|
||||
|
||||
class TopLevel {
|
||||
class Nested
|
||||
}
|
||||
interface Interface
|
||||
|
||||
private fun checkClass(
|
||||
clazz: KClass<*>,
|
||||
expectedQualifiedName: String?, expectedSimpleName: String?, expectedToStringName: String,
|
||||
expectedInstance: Any, expectedNotInstance: Any?
|
||||
) {
|
||||
assertEquals(expectedQualifiedName, clazz.qualifiedName)
|
||||
assertEquals(expectedSimpleName, clazz.simpleName)
|
||||
assertEquals(expectedToStringName, clazz.toString())
|
||||
|
||||
assertTrue(clazz.isInstance(expectedInstance))
|
||||
if (expectedNotInstance != null) assertTrue(!clazz.isInstance(expectedNotInstance))
|
||||
}
|
||||
|
||||
private fun checkInstanceClass(instance: Any, clazz: KClass<*>) {
|
||||
assertEquals(clazz, instance::class)
|
||||
}
|
||||
|
||||
private inline fun <reified T> checkReifiedClass(expectedClass: KClass<*>) {
|
||||
assertEquals(expectedClass, T::class)
|
||||
}
|
||||
|
||||
private inline fun <reified T> checkReifiedClass2(expectedClass: KClass<*>) {
|
||||
checkReifiedClass<T>(expectedClass)
|
||||
checkReifiedClass<T?>(expectedClass)
|
||||
}
|
||||
|
||||
// Like `run` but without inlining.
|
||||
private fun runNonInlining(block: () -> Unit) = block()
|
||||
|
||||
private fun <T> (suspend () -> T).runCoroutine() = startCoroutine(Continuation(EmptyCoroutineContext) { it.getOrThrow() })
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.kclass.kclass1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// FILE: main.kt
|
||||
@Test fun runTest() {
|
||||
App(testQualified = true)
|
||||
}
|
||||
|
||||
// FILE: app.kt
|
||||
|
||||
// Taken from:
|
||||
// https://github.com/SalomonBrys/kmffkn/blob/master/shared/main/kotlin/com/github/salomonbrys/kmffkn/app.kt
|
||||
|
||||
@DslMarker
|
||||
annotation class MyDsl
|
||||
|
||||
@MyDsl
|
||||
class DslMain {
|
||||
fun <T: Any> kClass(block: KClassDsl.() -> T): T = KClassDsl().block()
|
||||
}
|
||||
|
||||
@MyDsl
|
||||
class KClassDsl {
|
||||
inline fun <reified T: Any> of() = T::class
|
||||
}
|
||||
|
||||
fun <T: Any> dsl(block: DslMain.() -> T): T = DslMain().block()
|
||||
|
||||
class TestClass
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
class App(testQualified: Boolean) {
|
||||
|
||||
var type = dsl {
|
||||
kClass {
|
||||
//kClass { } // This should error if uncommented because of `@DslMarker`.
|
||||
of<TestClass>()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
assert(type.simpleName == "TestClass")
|
||||
if (testQualified)
|
||||
assert(type.qualifiedName == "codegen.kclass.kclass1.TestClass") // This is not really necessary, but always better :).
|
||||
|
||||
assert(String::class == String::class)
|
||||
assert(String::class != Int::class)
|
||||
|
||||
assert(TestClass()::class == TestClass()::class)
|
||||
assert(TestClass()::class == TestClass::class)
|
||||
|
||||
println("OK :D")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK :D
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
inline fun <reified R> kType() = typeOf<R>()
|
||||
|
||||
inline fun <reified R> kType(obj: R) = kType<R>()
|
||||
|
||||
fun box(): String {
|
||||
val obj = object {}
|
||||
val objType = kType(obj)
|
||||
|
||||
assertEquals("(non-denotable type)", objType.toString())
|
||||
assertEquals(obj::class, objType.classifier)
|
||||
|
||||
assertTrue(objType.arguments.isEmpty())
|
||||
assertFalse(objType.isMarkedNullable)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
inline fun <reified R> kType() = typeOf<R>()
|
||||
|
||||
inline fun <reified R> kType(obj: R) = kType<R>()
|
||||
|
||||
class C<T>
|
||||
class D
|
||||
|
||||
fun <T> kTypeForCWithTypeParameter() = kType<C<T>>()
|
||||
|
||||
class Outer<T> {
|
||||
companion object Friend
|
||||
inner class Inner<S>
|
||||
}
|
||||
|
||||
object Object
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("C<kotlin.Int?>", kType<C<Int?>>().toString())
|
||||
assertEquals("C<C<kotlin.Any>>", kType<C<C<Any>>>().toString())
|
||||
|
||||
assertEquals("C<T>", kTypeForCWithTypeParameter<D>().toString())
|
||||
assertEquals("Object", kType<Object>().toString())
|
||||
assertEquals("Outer.Friend", kType<Outer.Friend>().toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
inline fun <reified R> kType() = typeOf<R>()
|
||||
|
||||
class D
|
||||
class Outer<T> {
|
||||
companion object Friend
|
||||
inner class Inner<S>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val innerKType = kType<Outer<D>.Inner<String>>()
|
||||
assertEquals(Outer.Inner::class, innerKType.classifier)
|
||||
assertEquals(String::class, innerKType.arguments.first().type!!.classifier)
|
||||
assertEquals(D::class, innerKType.arguments.last().type!!.classifier)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
class C<T> {
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
fun foo() = typeOf<List<T>>()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val l = C<Int>().foo()
|
||||
assertEquals(List::class, l.classifier)
|
||||
val t = l.arguments.single().type!!.classifier
|
||||
assertTrue(t is KTypeParameter)
|
||||
assertFalse((t as KTypeParameter).isReified)
|
||||
assertEquals("T", (t as KTypeParameter).name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
fun <T> bar1() = typeOf<List<T>>()
|
||||
fun <T> bar2() = typeOf<List<T>>()
|
||||
|
||||
class D {
|
||||
fun <T> bar1() = typeOf<List<T>>()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t1 = bar1<Int>().arguments.single().type!!.classifier
|
||||
val t2 = bar2<Int>().arguments.single().type!!.classifier
|
||||
val t3 = D().bar1<Int>().arguments.single().type!!.classifier
|
||||
assertNotEquals(t1, t2)
|
||||
assertNotEquals(t1, t3)
|
||||
assertNotEquals(t2, t3)
|
||||
assertEquals(t1, bar1<Int>().arguments.single().type!!.classifier)
|
||||
assertEquals(t2, bar2<Int>().arguments.single().type!!.classifier)
|
||||
assertEquals(t3, D().bar1<Int>().arguments.single().type!!.classifier)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
fun <T> foo() = typeOf<List<T>>()
|
||||
|
||||
fun box(): String {
|
||||
val l = foo<Int>()
|
||||
assertEquals(List::class, l.classifier)
|
||||
val t = l.arguments.single().type!!.classifier
|
||||
assertTrue(t is KTypeParameter)
|
||||
assertFalse((t as KTypeParameter).isReified)
|
||||
assertEquals("T", (t as KTypeParameter).name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
inline fun <reified T : Comparable<T>> recursionInReified() = typeOf<List<T>>()
|
||||
|
||||
fun box(): String {
|
||||
val l = recursionInReified<Int>()
|
||||
assertEquals(List::class, l.classifier)
|
||||
assertEquals(Int::class, l.arguments.single().type!!.classifier)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
inline fun <reified T, R : T> reifiedUpperBound() = typeOf<List<R>>()
|
||||
|
||||
fun box(): String {
|
||||
val l = reifiedUpperBound<Any, Any>()
|
||||
assertEquals(List::class, l.classifier)
|
||||
val r = l.arguments.single().type!!.classifier
|
||||
assertTrue(r is KTypeParameter)
|
||||
assertFalse((r as KTypeParameter).isReified)
|
||||
assertEquals("R", (r as KTypeParameter).name)
|
||||
val t = (r as KTypeParameter).upperBounds.single().classifier
|
||||
assertTrue(t is KTypeParameter)
|
||||
assertTrue((t as KTypeParameter).isReified)
|
||||
assertEquals("T", (t as KTypeParameter).name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
run {
|
||||
println("lambda")
|
||||
}
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
lambda
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var str = "original"
|
||||
|
||||
val lambda = {
|
||||
println(str)
|
||||
}
|
||||
|
||||
lambda()
|
||||
|
||||
str = "changed"
|
||||
lambda()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
original
|
||||
changed
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda11
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val first = "first"
|
||||
val second = "second"
|
||||
|
||||
run {
|
||||
println(first)
|
||||
println(second)
|
||||
}
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
first
|
||||
second
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda12
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val lambda = { s1: String, s2: String ->
|
||||
println(s1)
|
||||
println(s2)
|
||||
}
|
||||
|
||||
lambda("one", "two")
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
one
|
||||
two
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda13
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
apply("foo") {
|
||||
println(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun apply(str: String, block: String.() -> Unit) {
|
||||
str.block()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
package codegen.lambda.lambda14
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals(foo()(), "foo1")
|
||||
assertEquals(foo(0)(), "foo2")
|
||||
}
|
||||
|
||||
fun foo() = { "foo1" }
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
package codegen.lambda.lambda14
|
||||
|
||||
fun foo(ignored: Int) = { "foo2" }
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
main(arrayOf("arg0"))
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
run {
|
||||
println(args[0])
|
||||
}
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arg0
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var str = "lambda"
|
||||
run {
|
||||
println(str)
|
||||
}
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
lambda
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val lambda = bar()
|
||||
lambda()
|
||||
lambda()
|
||||
}
|
||||
|
||||
fun bar(): () -> Unit {
|
||||
var x = Integer(0)
|
||||
|
||||
val lambda = {
|
||||
println(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
|
||||
x = x + 1
|
||||
|
||||
lambda()
|
||||
lambda()
|
||||
|
||||
println(x.toString())
|
||||
|
||||
return lambda
|
||||
}
|
||||
|
||||
class Integer(val value: Int) {
|
||||
override fun toString() = value.toString()
|
||||
operator fun plus(other: Int) = Integer(value + other)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
3
|
||||
4
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
foo {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Unit) {
|
||||
f(42)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val str = "captured"
|
||||
foo {
|
||||
println(it)
|
||||
println(str)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Unit) {
|
||||
f(42)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
42
|
||||
captured
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val x = foo {
|
||||
it + 1
|
||||
}
|
||||
println(x)
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Int) = f(42)
|
||||
@@ -0,0 +1 @@
|
||||
43
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val lambda1 = bar("first")
|
||||
val lambda2 = bar("second")
|
||||
|
||||
lambda1()
|
||||
lambda2()
|
||||
lambda1()
|
||||
lambda2()
|
||||
}
|
||||
|
||||
fun bar(str: String): () -> Unit {
|
||||
var x = Integer(0)
|
||||
|
||||
return {
|
||||
println(str)
|
||||
println(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
}
|
||||
|
||||
class Integer(val value: Int) {
|
||||
override fun toString() = value.toString()
|
||||
operator fun plus(other: Int) = Integer(value + other)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
first
|
||||
0
|
||||
second
|
||||
0
|
||||
first
|
||||
1
|
||||
second
|
||||
1
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val lambdas = ArrayList<() -> Unit>()
|
||||
|
||||
for (i in 0..1) {
|
||||
var x = Integer(0)
|
||||
val istr = i.toString()
|
||||
|
||||
lambdas.add {
|
||||
println(istr)
|
||||
println(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
}
|
||||
|
||||
val lambda1 = lambdas[0]
|
||||
val lambda2 = lambdas[1]
|
||||
|
||||
lambda1()
|
||||
lambda2()
|
||||
lambda1()
|
||||
lambda2()
|
||||
}
|
||||
|
||||
class Integer(val value: Int) {
|
||||
override fun toString() = value.toString()
|
||||
operator fun plus(other: Int) = Integer(value + other)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
@@ -0,0 +1,17 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
// To be tested with -g.
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-49360
|
||||
|
||||
fun testTrivialCreateBlock(result: Int): () -> Int {
|
||||
return (if (result == 0) { { 0 } } else null) ?: { result }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(0, testTrivialCreateBlock(0)())
|
||||
assertEquals(1, testTrivialCreateBlock(1)())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
// To be tested with -g.
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-49360
|
||||
|
||||
// The Flow code below is taken from kotlinx.coroutines (some unrelated details removed).
|
||||
|
||||
interface FlowCollector<in T> {
|
||||
suspend fun emit(value: T)
|
||||
}
|
||||
|
||||
interface Flow<out T> {
|
||||
suspend fun collect(collector: FlowCollector<T>)
|
||||
}
|
||||
|
||||
suspend inline fun <T> Flow<T>.collect(crossinline action: suspend (value: T) -> Unit): Unit =
|
||||
collect(object : FlowCollector<T> {
|
||||
override suspend fun emit(value: T) = action(value)
|
||||
})
|
||||
|
||||
inline fun <T> unsafeFlow(crossinline block: suspend FlowCollector<T>.() -> Unit): Flow<T> {
|
||||
return object : Flow<T> {
|
||||
override suspend fun collect(collector: FlowCollector<T>) {
|
||||
collector.block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R> Flow<T>.unsafeTransform(
|
||||
crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit
|
||||
): Flow<R> = unsafeFlow {
|
||||
collect { value ->
|
||||
return@collect transform(value)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend (value: T) -> R?): Flow<R> = unsafeTransform { value ->
|
||||
val transformed = transform(value) ?: return@unsafeTransform
|
||||
return@unsafeTransform emit(transformed)
|
||||
}
|
||||
|
||||
fun <T> flowOf(value: T): Flow<T> = unsafeFlow {
|
||||
emit(value)
|
||||
}
|
||||
|
||||
suspend fun <T> Flow<T>.toList(): List<T> {
|
||||
val result = mutableListOf<T>()
|
||||
collect {
|
||||
result.add(it)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Close to https://youtrack.jetbrains.com/issue/KT-49360:
|
||||
fun testWithFlowMapNotNull(flow: Flow<Boolean>): Flow<Block> {
|
||||
return flow.mapNotNull {
|
||||
if (it) Block({ 333 }) else null
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
lateinit var list1: List<Block>
|
||||
lateinit var list2: List<Block>
|
||||
|
||||
builder {
|
||||
list1 = testWithFlowMapNotNull(flowOf(true)).toList()
|
||||
list2 = testWithFlowMapNotNull(flowOf(false)).toList()
|
||||
}
|
||||
|
||||
assertEquals(1, list1.size)
|
||||
assertEquals(333, list1.single().block())
|
||||
|
||||
assertEquals(0, list2.size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
// To be tested with -g.
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-49360
|
||||
|
||||
class Block(val block: () -> Int)
|
||||
|
||||
fun testWrapBlockCreate(flag: Boolean): Block {
|
||||
return (if (flag) Block { 11 } else null) ?: Block { 22 }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(11, testWrapBlockCreate(true).block())
|
||||
assertEquals(22, testWrapBlockCreate(false).block())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.globalIsInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() {
|
||||
println(::s.isInitialized)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo()
|
||||
s = "zzz"
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
false
|
||||
true
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.inBaseClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A(val a: Int)
|
||||
|
||||
open class B {
|
||||
lateinit var a: A
|
||||
}
|
||||
|
||||
class C: B() {
|
||||
fun foo() { a = A(42) }
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val c = C()
|
||||
c.foo()
|
||||
println(c.a.a)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.initialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a = A()
|
||||
a.s = "zzz"
|
||||
println(a.foo())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
zzz
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.innerIsInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Foo {
|
||||
lateinit var bar: String
|
||||
|
||||
fun test(): String {
|
||||
return InnerSubclass().testInner()
|
||||
}
|
||||
|
||||
inner class InnerSubclass : Foo() {
|
||||
fun testInner(): String {
|
||||
// This is access to InnerSubclass.bar which is inherited from Foo.bar
|
||||
if (this::bar.isInitialized) return "Fail"
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Foo().test())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.isInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() {
|
||||
println(::s.isInitialized)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a = A()
|
||||
a.foo()
|
||||
a.s = "zzz"
|
||||
a.foo()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
false
|
||||
true
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localCapturedInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
|
||||
s = "zzz"
|
||||
println(foo())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
zzz
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localCapturedNotInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
|
||||
try {
|
||||
println(foo())
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
}
|
||||
println("Fail")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
lateinit var s: String
|
||||
s = "zzz"
|
||||
println(s)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
zzz
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localNotInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
lateinit var s: String
|
||||
|
||||
try {
|
||||
println(s)
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
}
|
||||
println("Fail")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.notInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a = A()
|
||||
try {
|
||||
println(a.foo())
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
}
|
||||
println("Fail")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.innerTakesCapturedFromOuter
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box() {
|
||||
var previous: Any? = null
|
||||
for (i in 0 .. 2) {
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
override fun toString() = i.toString()
|
||||
}
|
||||
|
||||
override fun toString() = Inner().toString()
|
||||
}
|
||||
if (previous != null) println(previous.toString())
|
||||
previous = Outer()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
box()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
0
|
||||
1
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.innerWithCapture
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(s: String): String {
|
||||
class Local {
|
||||
open inner class Inner() {
|
||||
open fun result() = s
|
||||
}
|
||||
}
|
||||
|
||||
return Local().Inner().result()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box("OK"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localFunctionCallFromLocalClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var x = 1
|
||||
fun local1() {
|
||||
x++
|
||||
}
|
||||
|
||||
class A {
|
||||
fun bar() {
|
||||
local1()
|
||||
}
|
||||
}
|
||||
A().bar()
|
||||
println("OK")
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localFunctionInLocalClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var x = 0
|
||||
class A {
|
||||
fun bar() {
|
||||
fun local() {
|
||||
class B {
|
||||
fun baz() {
|
||||
fun local2() {
|
||||
x++
|
||||
}
|
||||
local2()
|
||||
}
|
||||
}
|
||||
B().baz()
|
||||
}
|
||||
local()
|
||||
}
|
||||
}
|
||||
A().bar()
|
||||
println("OK")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localHierarchy
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(s: String): String {
|
||||
open class Local {
|
||||
fun f() = s
|
||||
}
|
||||
|
||||
open class Derived: Local() {
|
||||
fun g() = f()
|
||||
}
|
||||
|
||||
return Derived().g()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo("OK"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.noPrimaryConstructor
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(s: String): String {
|
||||
class Local {
|
||||
constructor(x: Int) {
|
||||
this.x = x
|
||||
}
|
||||
|
||||
constructor(z: String) {
|
||||
x = z.length
|
||||
}
|
||||
|
||||
val x: Int
|
||||
|
||||
fun result() = s
|
||||
}
|
||||
|
||||
return Local(42).result() + Local("zzz").result()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box("OK"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OKOK
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.objectExpressionInInitializer
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class Father {
|
||||
abstract inner class InClass {
|
||||
abstract fun work(): String
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Father() {
|
||||
val ChildInClass : InClass
|
||||
|
||||
init {
|
||||
ChildInClass = object : Father.InClass() {
|
||||
override fun work(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Child().ChildInClass.work()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.objectExpressionInProperty
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class Father {
|
||||
abstract inner class InClass {
|
||||
abstract fun work(): String
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Father() {
|
||||
val ChildInClass = object : Father.InClass() {
|
||||
override fun work(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Child().ChildInClass.work()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.tryCatch
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private fun foo() {
|
||||
val local =
|
||||
object {
|
||||
fun bar() {
|
||||
try {
|
||||
} catch (t: Throwable) {
|
||||
println(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
local.bar()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
foo()
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.virtualCallFromConstructor
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class WaitFor {
|
||||
init {
|
||||
condition()
|
||||
}
|
||||
|
||||
abstract fun condition(): Boolean;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val local = ""
|
||||
var result = "fail"
|
||||
val s = object : WaitFor() {
|
||||
|
||||
override fun condition(): Boolean {
|
||||
result = "OK"
|
||||
return result.length == 2
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
class ArraysConstructor {
|
||||
private val memberArray: IntArray
|
||||
constructor(int1: Int, int2: Int) {
|
||||
memberArray = IntArray(2)
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (constructor init):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
class ArraysDefault {
|
||||
private val memberArray = IntArray(2)
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (default value init):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
class ArraysInitBlock {
|
||||
private val memberArray : IntArray
|
||||
init {
|
||||
memberArray = IntArray(2)
|
||||
}
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (init block):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val array1 = (::ArraysConstructor)(1, 2)
|
||||
array1.log()
|
||||
array1.set( 3, 4)
|
||||
array1.log()
|
||||
|
||||
val array2 = (::ArraysDefault)(1, 2)
|
||||
array2.log()
|
||||
array2.set( 3, 4)
|
||||
array2.log()
|
||||
|
||||
val array3 = (::ArraysInitBlock)(1, 2)
|
||||
array3.log()
|
||||
array3.set( 3, 4)
|
||||
array3.log()
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.constructor0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
var field0:Int = 0;
|
||||
constructor(arg0:Int) {
|
||||
field0 = arg0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private var globalValue = 1
|
||||
var global:Int
|
||||
get() = globalValue
|
||||
set(value:Int) {globalValue = value}
|
||||
|
||||
fun globalTest(i:Int):Int {
|
||||
global += i
|
||||
return global
|
||||
}
|
||||
|
||||
|
||||
@Test fun runTest() {
|
||||
if (global != 1) throw Error()
|
||||
if (globalTest(41) != 42) throw Error()
|
||||
if (global != 42) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class B(val a:Int, b:Int) {
|
||||
constructor(pos:Int):this(1, pos) {}
|
||||
val pos = b + 1
|
||||
}
|
||||
|
||||
fun primaryConstructorCall(a:Int, b:Int) = B(a, b).pos
|
||||
|
||||
fun secondaryConstructorCall(a:Int) = B(a).pos
|
||||
|
||||
@Test fun runTest() {
|
||||
if (primaryConstructorCall(0xdeadbeef.toInt(), 41) != 42) throw Error()
|
||||
if (secondaryConstructorCall(41) != 42) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
var global: Int = 0
|
||||
get() {
|
||||
println("Get global = $field")
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
println("Set global = $value")
|
||||
field = value
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
var member: Int = 0
|
||||
get() {
|
||||
println("Get member = $field")
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
println("Set member = $value")
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest1() {
|
||||
global = 1
|
||||
|
||||
val test = TestClass()
|
||||
test.member = 42
|
||||
|
||||
global = test.member
|
||||
test.member = global
|
||||
}
|
||||
|
||||
@ThreadLocal
|
||||
val xInt = 42
|
||||
|
||||
@ThreadLocal
|
||||
val xString = "42"
|
||||
|
||||
@ThreadLocal
|
||||
val xAny = Any()
|
||||
|
||||
@Test fun runTest2() {
|
||||
assertEquals(42, xInt)
|
||||
assertEquals("42", xString)
|
||||
assertTrue(xAny is Any)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
Set global = 1
|
||||
Set member = 42
|
||||
Get member = 42
|
||||
Set global = 42
|
||||
Get global = 42
|
||||
Set member = 42
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user