Skip to content

Commit 7540250

Browse files
authored
Merge pull request #745 from zhelenskiy/fir-extended-checkers
Fir extended checkers
2 parents 53c8147 + 1f42382 commit 7540250

File tree

557 files changed

+614
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

557 files changed

+614
-560
lines changed

common/src/main/kotlin/component/KotlinEnvironment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class KotlinEnvironment(
4848
"-opt-in=kotlin.contracts.ExperimentalContracts",
4949
"-opt-in=kotlin.experimental.ExperimentalTypeInference",
5050
"-Xcontext-receivers",
51-
"-XXLanguage:+ExplicitBackingFields"
51+
"-Xreport-all-warnings",
52+
"-Xuse-fir-extended-checkers",
53+
"-XXLanguage:+ExplicitBackingFields",
5254
)
5355
}
5456

src/main/kotlin/com/compiler/server/compiler/components/CliUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
1212
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
1313
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
1414
import org.jetbrains.kotlin.psi.KtFile
15+
import java.io.File
1516
import java.nio.file.Path
16-
import java.nio.file.Paths
1717
import java.util.*
1818
import kotlin.io.path.*
1919

@@ -126,7 +126,7 @@ fun <T> usingTempDirectory(action: (path: Path) -> T): T {
126126
private fun getTempDirectory(): Path {
127127
val dir = System.getProperty("java.io.tmpdir")
128128
val sessionId = UUID.randomUUID().toString().replace("-", "")
129-
return Paths.get(dir, sessionId)
129+
return File(dir).canonicalFile.resolve(sessionId).toPath()
130130
}
131131

132132
fun List<KtFile>.writeToIoFiles(inputDir: Path): List<Path> {
@@ -137,4 +137,4 @@ fun List<KtFile>.writeToIoFiles(inputDir: Path): List<Path> {
137137
return ioFiles
138138
}
139139

140-
val PATH_SEPARATOR: String = java.io.File.pathSeparator
140+
val PATH_SEPARATOR: String = File.pathSeparator

src/main/kotlin/com/compiler/server/compiler/components/KotlinToJSTranslator.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class KotlinToJSTranslator(
9494
val filePaths = ioFiles.map { it.toFile().canonicalPath }
9595
val klibPath = (outputDir / "klib").toFile().canonicalPath
9696
val additionalCompilerArgumentsForKLib = listOf(
97+
"-Xreport-all-warnings",
98+
"-Xuse-fir-extended-checkers",
9799
"-Xir-only",
98100
"-Xir-produce-klib-dir",
99101
"-libraries=${kotlinEnvironment.JS_LIBRARIES.joinToString(PATH_SEPARATOR)}",
@@ -103,6 +105,8 @@ class KotlinToJSTranslator(
103105
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, filePaths + additionalCompilerArgumentsForKLib)
104106
.flatMap {
105107
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, listOf(
108+
"-Xreport-all-warnings",
109+
"-Xuse-fir-extended-checkers",
106110
"-Xir-only",
107111
"-Xir-produce-js",
108112
"-Xir-dce",
@@ -152,6 +156,8 @@ class KotlinToJSTranslator(
152156
}
153157
} ?: emptyList()
154158
val additionalCompilerArgumentsForKLib: List<String> = listOf(
159+
"-Xreport-all-warnings",
160+
"-Xuse-fir-extended-checkers",
155161
"-Xwasm",
156162
"-Xir-produce-klib-dir",
157163
"-libraries=${dependencies.joinToString(PATH_SEPARATOR)}",
@@ -162,6 +168,8 @@ class KotlinToJSTranslator(
162168
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, filePaths + additionalCompilerArgumentsForKLib)
163169
.flatMap {
164170
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, listOf(
171+
"-Xreport-all-warnings",
172+
"-Xuse-fir-extended-checkers",
165173
"-Xwasm",
166174
"-Xwasm-generate-wat",
167175
"-Xir-produce-js",

src/test/kotlin/com/compiler/server/HighlightTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.compiler.server.base.BaseExecutorTest
44
import com.compiler.server.base.errorContains
55
import com.compiler.server.base.warningContains
66
import org.junit.jupiter.api.Assertions
7-
import org.junit.jupiter.api.Disabled
87
import org.junit.jupiter.api.Test
98

109
class HighlightTest : BaseExecutorTest() {
@@ -27,22 +26,22 @@ class HighlightTest : BaseExecutorTest() {
2726
Assertions.assertTrue(highlights.isEmpty())
2827
}
2928

30-
@Test @Disabled
29+
@Test
3130
fun `base highlight unused variable`() {
3231
val highlights = highlight("fun main() {\n\tval a = \"d\"\n}")
33-
warningContains(highlights, "Variable 'a' is never used")
32+
warningContains(highlights, "Variable is unused")
3433
}
3534

36-
@Test @Disabled
35+
@Test
3736
fun `base highlight unused variable js`() {
3837
val highlights = highlightJS("fun main() {\n\tval a = \"d\"\n}")
39-
warningContains(highlights, "Variable 'a' is never used")
38+
warningContains(highlights, "Variable is unused")
4039
}
4140

42-
@Test @Disabled
41+
@Test
4342
fun `base highlight unused variable wasm`() {
4443
val highlights = highlightWasm("fun main() {\n\tval a = \"d\"\n}")
45-
warningContains(highlights, "Variable 'a' is never used")
44+
warningContains(highlights, "Variable is unused")
4645
}
4746

4847
@Test

src/test/kotlin/com/compiler/server/JvmRunnerTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,33 @@ class JvmRunnerTest : BaseExecutorTest() {
107107
result.compilerDiagnostics[0].message
108108
)
109109
}
110+
111+
@Test
112+
fun `warnings after exception`() {
113+
// language=kotlin
114+
val result = run(
115+
"""
116+
fun main() {
117+
println("")g
118+
var someVar = 1
119+
}
120+
""".trimIndent(), ""
121+
)
122+
123+
assertContains(result.compilerDiagnostics.map { it.message }, "Variable is unused.")
124+
}
125+
126+
@Test
127+
fun `warnings without exception`() {
128+
// language=kotlin
129+
val result = run(
130+
"""
131+
fun main() {
132+
println("")
133+
var someVar = 1
134+
}
135+
""".trimIndent(), "")
136+
137+
assertContains(result.compilerDiagnostics.map { it.message }, "Variable is unused.")
138+
}
110139
}

src/test/kotlin/com/compiler/server/ResourceE2ECompileTest.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.compiler.server
22

33
import com.compiler.server.generator.generateSingleProject
4-
import com.compiler.server.model.ExecutionResult
5-
import com.compiler.server.model.ProjectType
4+
import com.compiler.server.model.*
65
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7-
import org.junit.jupiter.api.Disabled
86
import org.junit.jupiter.api.Test
97
import org.springframework.beans.factory.annotation.Value
108
import org.springframework.boot.test.context.SpringBootTest
@@ -34,15 +32,21 @@ class ResourceE2ECompileTest : BaseResourceCompileTest {
3432
generateSingleProject(code, projectType = platform)
3533
)
3634

35+
val resultClass = when (platform) {
36+
ProjectType.JUNIT -> JunitExecutionResult::class.java
37+
ProjectType.JAVA -> JvmExecutionResult::class.java
38+
ProjectType.JS, ProjectType.CANVAS, ProjectType.JS_IR -> TranslationJSResult::class.java
39+
ProjectType.WASM, ProjectType.COMPOSE_WASM -> TranslationWasmResult::class.java
40+
}
3741
val result = RestTemplate().postForObject(
38-
"${getHost()}$url", HttpEntity(body, headers), ExecutionResult::class.java
42+
"${getHost()}$url", HttpEntity(body, headers), resultClass
3943
)
4044

4145
return result ?:
4246
throw IllegalStateException("Result is null")
4347
}
4448

45-
@Test @Disabled
49+
@Test
4650
fun `http requests from resource folder`() {
4751
checkResourceExamples(listOf(testDirJVM, testDirJS)) { result, file ->
4852
val json = jacksonObjectMapper().writeValueAsString(result)
@@ -89,5 +93,6 @@ private fun File.isInconsistentOutput(): Boolean {
8993
".inWholeNanoseconds",
9094
" measureTime {",
9195
" measureTimedValue {",
96+
"LocalDate.now()",
9297
).any { code.contains(it) }
9398
}

src/test/resources/test-compile-data/jvm/kotlin-web-site/basic-syntax/5ec261721162729866abc1e8f7293ef4.29.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ fun getStringLength(obj: Any): Int? {
1010
}
1111
//sampleEnd
1212

13+
data object Some
14+
1315
fun main() {
1416
fun printLength(obj: Any) {
1517
println("Getting the length of '$obj'. Result: ${getStringLength(obj) ?: "Error: The object is not a string"} ")
1618
}
1719
printLength("Incomprehensibilities")
1820
printLength(1000)
19-
printLength(listOf(Any()))
21+
printLength(listOf(Some))
2022
}

src/test/resources/test-compile-data/jvm/kotlin-web-site/basic-syntax/5ec261721162729866abc1e8f7293ef4.30.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ fun getStringLength(obj: Any): Int? {
77
}
88
//sampleEnd
99

10+
data object Some
11+
1012
fun main() {
1113
fun printLength(obj: Any) {
1214
println("Getting the length of '$obj'. Result: ${getStringLength(obj) ?: "Error: The object is not a string"} ")
1315
}
1416
printLength("Incomprehensibilities")
1517
printLength(1000)
16-
printLength(listOf(Any()))
18+
printLength(listOf(Some))
1719
}

src/test/resources/test-compile-data/jvm/kotlin-web-site/java-to-kotlin-collections-guide/57cc463d64510535f01862401a66c55d.7.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Request(
1+
data class Request(
22
val url: String,
33
val responseCode: Int
44
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fun main(args: Array<String>) {
22
//sampleStart
33
val array = arrayOf("a", "b", "c")
4-
println(array.toString()) // JVM implementation: type-and-hash gibberish
4+
println(array.toString().substringBefore('@')) // JVM implementation: type-and-hash gibberish
55
println(array.contentToString()) // nicely formatted as list
66
//sampleEnd
77
}

0 commit comments

Comments
 (0)