mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Merge pull request #9829 from smowton/smowton/fix/kotlin-underscore-parameter-names
Kotlin: Don't extract a name for a '_' parameter
This commit is contained in:
@@ -4,6 +4,7 @@ import com.github.codeql.comments.CommentExtractor
|
||||
import com.github.codeql.utils.*
|
||||
import com.github.codeql.utils.versions.functionN
|
||||
import com.github.codeql.utils.versions.getIrStubFromDescriptor
|
||||
import com.github.codeql.utils.versions.isUnderscoreParameter
|
||||
import com.semmle.extractor.java.OdasaOutput
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.parents
|
||||
@@ -642,7 +643,7 @@ open class KotlinFileExtractor(
|
||||
if (extractTypeAccess) {
|
||||
extractTypeAccessRecursive(substitutedType, location, id, -1)
|
||||
}
|
||||
val syntheticParameterNames = (vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true
|
||||
val syntheticParameterNames = isUnderscoreParameter(vp) || ((vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true)
|
||||
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg, syntheticParameterNames)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) =
|
||||
try {
|
||||
DescriptorToSourceUtils.getSourceFromDescriptor(vp.descriptor)
|
||||
?.safeAs<KtParameter>()?.isSingleUnderscore == true
|
||||
} catch(e: NotImplementedError) {
|
||||
// Some kinds of descriptor throw in `getSourceFromDescriptor` as that method is not normally expected to
|
||||
// be applied to synthetic functions.
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) = vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
|
||||
fun isUnderscoreParameter(vp: IrValueParameter) = vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER
|
||||
Reference in New Issue
Block a user