Merge pull request #11310 from tamasvajk/kotlin-dead-code

Kotlin: Exclude .kt files from dead code queries
This commit is contained in:
Chris Smowton
2022-11-17 10:10:51 +00:00
committed by GitHub
8 changed files with 39 additions and 0 deletions

View File

@@ -14,6 +14,8 @@ import semmle.code.java.deadcode.DeadCode
from DeadClass c, Element origin, string reason
where
not c.getFile().isKotlinSourceFile() and
not origin.getFile().isKotlinSourceFile() and
if exists(DeadRoot root | root = c.getADeadRoot() | not root = c.getACallable())
then (
// Report a list of the dead roots.

View File

@@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
from DeadField f, Element origin, string reason
where
not f.getFile().isKotlinSourceFile() and
not origin.getFile().isKotlinSourceFile() and
not f.isInDeadScope() and
if f.getAnAccess() instanceof FieldRead
then (

View File

@@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
from DeadMethod c, Callable origin, string reason
where
not c.getFile().isKotlinSourceFile() and
not origin.getFile().isKotlinSourceFile() and
not c.isInDeadScope() and
if exists(DeadRoot deadRoot | deadRoot = getADeadRoot(c) | deadRoot.getSourceDeclaration() != c)
then (

View File

@@ -0,0 +1 @@
DeadCode/DeadClass.ql

View File

@@ -0,0 +1 @@
DeadCode/DeadMethod.ql

View File

@@ -0,0 +1,31 @@
sealed interface DbAddexpr
class Label<T> {
}
fun <T> getFreshIdLabel(): Label<T> {
return Label()
}
fun foo(): Label<DbAddexpr> {
val x = getFreshIdLabel<DbAddexpr>()
return x
}
fun main1() {
print(foo())
}
class Foo {
data class DC(val x: Int, val y: Int)
fun foo() {
val dc = DC(3, 4)
print(dc.x)
print(dc.y)
}
}
fun main2() {
Foo().foo()
}