Skip to content

Commit d4b0163

Browse files
committed
Kotlin: Don't extract a name for a '_' parameter
I can't reproduce the exact circumstances, but these sometimes get "<anonymous parameter X>" names and sometimes get "$noName_X" names. Whichever way, avoiding extracting a synthetic name seems safest; anyone finding the .class file and not reading the metadata indicating it came from a `_` will extract the binary name selected, or else QL will invent a name.
1 parent 7fbe4f8 commit d4b0163

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ open class KotlinFileExtractor(
642642
if (extractTypeAccess) {
643643
extractTypeAccessRecursive(substitutedType, location, id, -1)
644644
}
645-
val syntheticParameterNames = (vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true
645+
val syntheticParameterNames = vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER || ((vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true)
646646
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg, syntheticParameterNames)
647647
}
648648
}

java/ql/test/kotlin/library-tests/exprs/PrintAst.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,7 +3583,7 @@ funcExprs.kt:
35833583
# 27| 2: [Method] invoke
35843584
# 27| 3: [TypeAccess] int
35853585
#-----| 4: (Parameters)
3586-
# 27| 0: [Parameter] <anonymous parameter 0>
3586+
# 27| 0: [Parameter] p0
35873587
# 27| 0: [TypeAccess] int
35883588
# 27| 5: [BlockStmt] { ... }
35893589
# 27| 0: [ReturnStmt] return ...
@@ -3629,9 +3629,9 @@ funcExprs.kt:
36293629
# 30| 2: [Method] invoke
36303630
# 30| 3: [TypeAccess] int
36313631
#-----| 4: (Parameters)
3632-
# 30| 0: [Parameter] <anonymous parameter 0>
3632+
# 30| 0: [Parameter] p0
36333633
# 30| 0: [TypeAccess] int
3634-
# 30| 1: [Parameter] <anonymous parameter 1>
3634+
# 30| 1: [Parameter] p1
36353635
# 30| 0: [TypeAccess] int
36363636
# 30| 5: [BlockStmt] { ... }
36373637
# 30| 0: [ReturnStmt] return ...
@@ -3652,9 +3652,9 @@ funcExprs.kt:
36523652
# 31| 2: [Method] invoke
36533653
# 31| 3: [TypeAccess] int
36543654
#-----| 4: (Parameters)
3655-
# 31| 0: [Parameter] <anonymous parameter 0>
3655+
# 31| 0: [Parameter] p0
36563656
# 31| 0: [TypeAccess] int
3657-
# 31| 1: [Parameter] <anonymous parameter 1>
3657+
# 31| 1: [Parameter] p1
36583658
# 31| 0: [TypeAccess] int
36593659
# 31| 5: [BlockStmt] { ... }
36603660
# 31| 0: [ReturnStmt] return ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.kt:5:9:5:9 | p0 | p0 |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
3+
var x: Int
4+
get() = 1
5+
set(_) { }
6+
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from Parameter p
4+
where p.getCallable().fromSource()
5+
select p, p.getName()

0 commit comments

Comments
 (0)