Skip to content

Commit b198c08

Browse files
committed
Add more tests for header compilation.
^KT-78422
1 parent 1c5dd2f commit b198c08

File tree

10 files changed

+209
-0
lines changed

10 files changed

+209
-0
lines changed

compiler/fir/analysis-tests/testData/resolve/headerMode/classDeclaration.fir.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ FILE: classDeclaration.kt
2121

2222
public final fun funD(): R|kotlin/Int|
2323

24+
public final inline fun funE(): R|kotlin/String| {
25+
local final fun funF(): R|kotlin/String|
26+
27+
^funE R|<local>/funF|()
28+
}
29+
2430
}
2531
public abstract interface B : R|kotlin/Any| {
2632
public open fun funA(): R|kotlin/String|

compiler/fir/analysis-tests/testData/resolve/headerMode/classDeclaration.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class A {
2525
}
2626

2727
fun funD() = 1 + 2
28+
29+
inline fun funE(): String {
30+
fun funF() = "funF body"
31+
return funF()
32+
}
2833
}
2934

3035
interface B {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FILE: constructorDeclaration.kt
2+
public final class A : R|kotlin/Any| {
3+
public constructor(a: R|kotlin/String|, b: R|kotlin/Int|): R|A| {
4+
super<R|kotlin/Any|>()
5+
}
6+
7+
public final val a: R|kotlin/String| = R|<local>/a|
8+
public get(): R|kotlin/String|
9+
10+
public final val b: R|kotlin/Int| = R|<local>/b|
11+
public get(): R|kotlin/Int|
12+
13+
public constructor(e: R|kotlin/String|): R|A| {
14+
this<R|A|>(R|<local>/e|, Int(0))
15+
lval message: R|kotlin/String| = String(Secondary constructor body)
16+
}
17+
18+
public constructor(): R|A| {
19+
this<R|A|>(String())
20+
lval message: R|kotlin/String| = String(Secondary constructor body with delegated constructor call)
21+
}
22+
23+
}
24+
public final class B : R|kotlin/Any| {
25+
private constructor(a: R|kotlin/String|, b: R|kotlin/Int|): R|B| {
26+
super<R|kotlin/Any|>()
27+
}
28+
29+
public final val a: R|kotlin/String| = R|<local>/a|
30+
public get(): R|kotlin/String|
31+
32+
public final val b: R|kotlin/Int| = R|<local>/b|
33+
public get(): R|kotlin/Int|
34+
35+
public constructor(e: R|kotlin/String|): R|B| {
36+
this<R|B|>(R|<local>/e|, Int(0))
37+
lval message: R|kotlin/String| = String(Secondary constructor body)
38+
}
39+
40+
public constructor(): R|B| {
41+
this<R|B|>(String())
42+
lval message: R|kotlin/String| = String(Secondary constructor body with delegated constructor call)
43+
}
44+
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// FIR_DUMP
3+
class A(val a: String, val b: Int) {
4+
constructor(e: String): this(e, 0) {
5+
val message = "Secondary constructor body"
6+
}
7+
constructor(): this("") {
8+
val message = "Secondary constructor body with delegated constructor call"
9+
}
10+
}
11+
12+
class B private constructor(val a: String, val b: Int) {
13+
constructor(e: String): this(e, 0) {
14+
val message = "Secondary constructor body"
15+
}
16+
constructor(): this("") {
17+
val message = "Secondary constructor body with delegated constructor call"
18+
}
19+
}
20+
21+
/* GENERATED_FIR_TAGS: classDeclaration, functionDeclaration, primaryConstructor, propertyDeclaration,
22+
secondaryConstructor */
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FILE: enumClassDeclaration.kt
2+
public final enum class A : R|kotlin/Enum<A>| {
3+
private constructor(): R|A| {
4+
super<R|kotlin/Enum<A>|>()
5+
}
6+
7+
public final static enum entry EAST: R|A|
8+
public final static enum entry WEST: R|A|
9+
public final static fun values(): R|kotlin/Array<A>|
10+
11+
public final static fun valueOf(value: R|kotlin/String|): R|A|
12+
13+
public final static val entries: R|kotlin/enums/EnumEntries<A>|
14+
public get(): R|kotlin/enums/EnumEntries<A>|
15+
16+
}
17+
public final enum class B : R|kotlin/Enum<B>| {
18+
private constructor(): R|B| {
19+
super<R|kotlin/Enum<B>|>()
20+
}
21+
22+
public final static enum entry NORTH: R|B| = object : R|B| {
23+
private constructor(): R|<anonymous>| {
24+
super<R|B|>()
25+
}
26+
27+
public open override fun getString(): R|kotlin/String|
28+
29+
}
30+
31+
public final static enum entry SOUTH: R|B| = object : R|B| {
32+
private constructor(): R|<anonymous>| {
33+
super<R|B|>()
34+
}
35+
36+
public open override fun getString(): R|kotlin/String|
37+
38+
}
39+
40+
public abstract fun getString(): R|kotlin/String|
41+
42+
public final static fun values(): R|kotlin/Array<B>|
43+
44+
public final static fun valueOf(value: R|kotlin/String|): R|B|
45+
46+
public final static val entries: R|kotlin/enums/EnumEntries<B>|
47+
public get(): R|kotlin/enums/EnumEntries<B>|
48+
49+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// FIR_DUMP
3+
enum class A {
4+
EAST,
5+
WEST
6+
}
7+
8+
enum class B {
9+
NORTH {
10+
override fun getString() = "north"
11+
},
12+
SOUTH {
13+
override fun getString(): String {
14+
return "south"
15+
}
16+
};
17+
18+
abstract fun getString(): String
19+
}
20+
21+
/* GENERATED_FIR_TAGS: enumDeclaration, enumEntry */

compiler/fir/analysis-tests/testData/resolve/headerMode/functionDeclaration.fir.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,23 @@ FILE: functionDeclaration.kt
1111

1212
private final fun funC(): R|kotlin/String|
1313
public final fun funD(): R|kotlin/Int|
14+
public final inline fun funE(): R|kotlin/String| {
15+
local final fun funF(): R|kotlin/String|
16+
17+
^funE R|<local>/funF|()
18+
}
19+
public final inline fun funG(): R|kotlin/String| {
20+
local final class classA : R|kotlin/Any| {
21+
public constructor(): R|<local>/classA| {
22+
super<R|kotlin/Any|>()
23+
}
24+
25+
public final fun funH(): R|kotlin/String|
26+
27+
}
28+
29+
lval a: R|<local>/classA| = R|<local>/classA.classA|()
30+
^funG R|<local>/a|.R|<local>/funH|()
31+
}
32+
public final fun funI(): R|kotlin/Int|
33+
public final fun funJ(): R|kotlin/String|

compiler/fir/analysis-tests/testData/resolve/headerMode/functionDeclaration.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import kotlin.contracts.ExperimentalContracts
44
import kotlin.contracts.contract
55

6+
// Public function
67
fun funA(): String {
78
return "funA body"
89
}
910

11+
// Inline function
1012
inline fun funB(): String {
1113
return "funB body"
1214
}
1315

16+
// Function with contract
1417
@OptIn(ExperimentalContracts::class)
1518
fun isNotNull(value: Any?): Boolean {
1619
contract {
@@ -19,11 +22,38 @@ fun isNotNull(value: Any?): Boolean {
1922
return value != null
2023
}
2124

25+
// Private function
2226
private fun funC(): String {
2327
return "funC body"
2428
}
2529

30+
// Implicit return type
2631
fun funD() = 1 + 2
2732

33+
// Function inside a function
34+
inline fun funE(): String {
35+
fun funF(): String {
36+
return "funF body"
37+
}
38+
return funF()
39+
}
40+
41+
// Class inside a function
42+
inline fun funG(): String {
43+
class classA {
44+
fun funH() = "funH body"
45+
}
46+
val a = classA()
47+
return a.funH()
48+
}
49+
50+
// Implicit type reference from another function.
51+
fun funI() = funD()
52+
53+
fun funJ(): String {
54+
inline fun funK() = "funK body"
55+
return funK()
56+
}
57+
2858
/* GENERATED_FIR_TAGS: classReference, contractConditionalEffect, contracts, functionDeclaration, inline, nullableType,
2959
stringLiteral */

compiler/fir/analysis-tests/testData/resolve/headerMode/objectDeclaration.fir.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ FILE: objectDeclaration.kt
2121

2222
public final fun funD(): R|kotlin/Int|
2323

24+
public final inline fun funE(): R|kotlin/String| {
25+
local final fun funF(): R|kotlin/String|
26+
27+
^funE R|<local>/funF|()
28+
}
29+
2430
}

compiler/fir/analysis-tests/testData/resolve/headerMode/objectDeclaration.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ object A {
2525
}
2626

2727
fun funD() = 1 + 2
28+
29+
inline fun funE(): String {
30+
fun funF() = "funF body"
31+
return funF()
32+
}
2833
}
2934

3035
/* GENERATED_FIR_TAGS: classReference, contractConditionalEffect, contracts, functionDeclaration, inline, nullableType,

0 commit comments

Comments
 (0)