Skip to content

Commit 1d2087b

Browse files
authored
Merge pull request github#10949 from tamasvajk/kotlin-underscore-var
Kotlin: exclude Kotlin files from `java/underscore-identifier`
2 parents 86e99c4 + d585839 commit 1d2087b

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

java/ql/src/Compatibility/JDK9/UnderscoreIdentifier.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class IdentifierElement extends Element {
2222

2323
from IdentifierElement e, string msg
2424
where
25-
e.fromSource() and
25+
e.getCompilationUnit().isJavaSourceFile() and
2626
not e.(Constructor).isDefaultConstructor() and
2727
(
2828
e.getName() = "_" and
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun fn() {
2+
try {
3+
val l = listOf(1, 2, 3)
4+
l.forEachIndexed { index, _ -> println(index) }
5+
6+
val p = Pair(1, 2)
7+
val (first, _) = p
8+
} catch (_: Exception) {
9+
// expected
10+
}
11+
}

java/ql/test/kotlin/query-tests/UnderscoreIdentifier/UnderscoreIdentifier.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Compatibility/JDK9/UnderscoreIdentifier.ql
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Test.kt:3:9:3:31 | List<Integer> l |
2+
| Test.kt:4:28:4:32 | index |
3+
| Test.kt:4:35:4:35 | p1 |
4+
| Test.kt:6:9:6:26 | Pair<Integer,Integer> p |
5+
| Test.kt:7:14:7:18 | int first |
6+
| Test.kt:7:26:7:26 | Pair<Integer,Integer> tmp0_container |
7+
| Test.kt:8:14:8:25 | Exception _ |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import java
2+
3+
query predicate variables(Variable v) { v.fromSource() }

0 commit comments

Comments
 (0)