Skip to content

Commit e6b18c3

Browse files
Godinantonioaversa
andauthored
SONARKT-550 Upgrade Kotlin compiler to 2.1.20
Co-authored-by: Antonio Aversa <[email protected]>
1 parent ef468ad commit e6b18c3

File tree

16 files changed

+279
-132
lines changed

16 files changed

+279
-132
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ group=org.sonarsource.kotlin
22
version=3.1.0-SNAPSHOT
33
description=Code Analyzer for Kotlin
44
projectTitle=Kotlin
5-
kotlinVersion=2.1.10
5+
kotlinVersion=2.1.20
66
org.gradle.jvmargs=-Xmx4096M

gradle/verification-metadata.xml

Lines changed: 128 additions & 115 deletions
Large diffs are not rendered by default.

its/ruling/src/test/resources/expected/kotlin/corda/kotlin-S1874.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"kotlin-corda-project:sources/kotlin/corda/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt": [
2121
335
2222
],
23-
"kotlin-corda-project:sources/kotlin/corda/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt": [
24-
48
25-
],
2623
"kotlin-corda-project:sources/kotlin/corda/core/src/main/kotlin/net/corda/core/utilities/ProgressTracker.kt": [
2724
52
2825
],

its/ruling/src/test/resources/expected/kotlin/kotlin/kotlin-S1128.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@
607607
34,
608608
35
609609
],
610+
"kotlin-kotlin-project:sources/kotlin/kotlin/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KotlinReferenceContributor.kt": [
611+
21
612+
],
610613
"kotlin-kotlin-project:sources/kotlin/kotlin/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/declarationsSearch/declarationSearchUtil.kt": [
611614
28
612615
],

its/ruling/src/test/resources/expected/kotlin/kotlin/kotlin-S6619.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@
347347
"kotlin-kotlin-project:sources/kotlin/kotlin/libraries/examples/kotlin-jsr223-local-example/src/test/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineIT.kt": [
348348
137
349349
],
350-
"kotlin-kotlin-project:sources/kotlin/kotlin/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt": [
351-
68
352-
],
353350
"kotlin-kotlin-project:sources/kotlin/kotlin/libraries/stdlib/common/src/generated/_Arrays.kt": [
354351
1250,
355352
1780

kotlin-checks-test-sources/src/main/kotlin/checks/DeprecatedCodeUsedCheckSample.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,42 @@ typealias DeprecatedString = String
6969

7070
@Deprecated("")
7171
private operator fun DeprecatedString.minus(s: String) = this + s // Noncompliant
72+
73+
class DeprecatedParameterUsedInFollowingParameter(
74+
@Deprecated("This is deprecated") val deprecatedParameter: String, // Compliant: not used, but declared
75+
val anotherParameterUsingDeprecatedOne: Int = deprecatedParameter.length, // Compliant: what is deprecated is the generated property, not the parameter itself
76+
) {
77+
val x = deprecatedParameter.length // Noncompliant
78+
79+
init {
80+
println(deprecatedParameter.length) // Noncompliant
81+
}
82+
}
83+
84+
// region top-level non compliant scenario
85+
86+
@Deprecated("This function is deprecated, use newFunction instead", ReplaceWith("deprecatedCodeUsed_newFunction()"))
87+
fun deprecatedCodeUsed_topLevel() {
88+
println("This is the old function.")
89+
}
90+
91+
fun deprecatedCodeUsed_newFunction() {
92+
println("This is the new function.")
93+
}
94+
95+
var deprecatedCodeUsed_var = deprecatedCodeUsed_topLevel() // Noncompliant
96+
97+
// endregion
98+
99+
fun nestedFunctions() {
100+
@Deprecated("This function is deprecated, use newFunction instead", ReplaceWith("newFunction()"))
101+
fun oldFunction() {
102+
println("This is the old function.")
103+
}
104+
105+
fun newFunction() {
106+
println("This is the new function.")
107+
}
108+
109+
oldFunction() // FN
110+
}

kotlin-checks-test-sources/src/main/kotlin/checks/UnnecessaryImportsCheckSample.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ import operators.remAssign // FN
9292
import operators.ResourceLoader
9393
import operators.provideDelegate // Compliant
9494

95+
import otherpackage.ClassUsedViaConstructorReference1
96+
import otherpackage.ClassUsedViaConstructorReference2
97+
import otherpackage.ClassUsedViaConstructorReference3
98+
import otherpackage.functionTakingAny
99+
95100

96101
class MyUI {
97102
fun <T> bindResource(id: ResourceID<T>): ResourceLoader<T> {
@@ -183,6 +188,12 @@ class UnnecessaryImportsCheckSample {
183188
fun bar() {
184189

185190
}
191+
192+
class ConstructorReference(val value: Any = ::ClassUsedViaConstructorReference1) {
193+
fun constructorReference(value: Any = ::ClassUsedViaConstructorReference2) {
194+
functionTakingAny(value = ::ClassUsedViaConstructorReference3)
195+
}
196+
}
186197
}
187198

188199
class ChildClass1A: java.util.Date()
@@ -200,3 +211,4 @@ inline fun <T> remember(calculation: () -> T): T = TODO()
200211
private fun state() = object : State<String> {
201212
override val value = "XY"
202213
}
214+

kotlin-checks-test-sources/src/main/kotlin/checks/UnnecessaryImportsCheckSampleNoSemantics.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ import operators.divAssign // FN
8282
import operators.remAssign // FN
8383
import operators.provideDelegate // FN due to missing binding context
8484

85+
import otherpackage.ClassUsedViaConstructorReference1
86+
import otherpackage.ClassUsedViaConstructorReference2
87+
import otherpackage.ClassUsedViaConstructorReference3
88+
import otherpackage.functionTakingAny
89+
8590
class SomeClassWithDelegateNoSemantics(var delegate: OperatorsContainer) {
8691
val someProperty: String by delegate
8792

@@ -154,8 +159,15 @@ class UnnecessaryImportsCheckSampleNoSemantics {
154159
fun bar() {
155160

156161
}
162+
163+
class ConstructorReference(val value: Any = ::ClassUsedViaConstructorReference1) {
164+
fun constructorReference(value: Any = ::ClassUsedViaConstructorReference2) {
165+
functionTakingAny(value = ::ClassUsedViaConstructorReference3)
166+
}
167+
}
157168
}
158169

159170
class ChildClass1B: java.util.Date()
160171
class ChildClass2B: Timer()
161172
class ClassInSameFileB
173+

kotlin-checks-test-sources/src/main/kotlin/checks/UnnecessaryImportsCheckSamplePartialSemantics.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ import java.beans.*
4545
import kotlin.test.*
4646
import kotlin.* // Noncompliant {{Remove this redundant import.}}
4747

48+
import otherpackage.ClassUsedViaConstructorReference1
49+
import otherpackage.ClassUsedViaConstructorReference2
50+
import otherpackage.ClassUsedViaConstructorReference3
51+
import otherpackage.functionTakingAny
52+
4853
class UnnecessaryImportsCheckSamplePartialSemantics {
4954
fun foo() {
5055
StringBuilder()
@@ -93,4 +98,10 @@ class UnnecessaryImportsCheckSamplePartialSemantics {
9398
fun bar() {
9499

95100
}
101+
102+
class ConstructorReference(val value: Any = ::ClassUsedViaConstructorReference1) {
103+
fun constructorReference(value: Any = ::ClassUsedViaConstructorReference2) {
104+
functionTakingAny(value = ::ClassUsedViaConstructorReference3)
105+
}
106+
}
96107
}

kotlin-checks-test-sources/src/main/kotlin/checks/UselessNullCheckCheckSample.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package checks
22

3-
import kotlinx.coroutines.CoroutineScope
4-
import java.io.IOException
5-
import java.net.HttpURLConnection
63
import java.util.Arrays
74
import java.util.WeakHashMap
85
import java.util.concurrent.locks.ReentrantReadWriteLock
96
import kotlin.concurrent.read
10-
import kotlin.coroutines.CoroutineContext
7+
import kotlin.test.asserter
118

129
class UselessNullCheckCheckSample {
1310

@@ -138,3 +135,15 @@ private class FooBar(
138135
private fun <T> testParametrised(list: List<T>): Int? {
139136
return list.first()?.hashCode()
140137
}
138+
139+
class NullableGeneric {
140+
fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
141+
contract { returns() implies (actual != null) } // Compliant: actual is nullable
142+
asserter.assertNotNull(message, actual)
143+
return actual!!
144+
}
145+
146+
fun returns(): NullableGeneric { throw NotImplementedError() }
147+
infix fun contract(block: () -> Unit) { }
148+
infix fun <T> T.implies(value: Boolean) { }
149+
}

0 commit comments

Comments
 (0)