mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Merge pull request #10328 from tamasvajk/kotlin-kfunction-fix
Kotlin: fix `KFunctionX.invoke` extraction
This commit is contained in:
@@ -1333,6 +1333,14 @@ open class KotlinFileExtractor(
|
||||
val receiverClass = receiverType.classifier.owner as? IrClass ?: return listOf()
|
||||
val ancestorTypes = ArrayList<IrSimpleType>()
|
||||
|
||||
// KFunctionX doesn't implement FunctionX on versions before 1.7.0:
|
||||
if ((callTarget.name.asString() == "invoke") &&
|
||||
(receiverClass.fqNameWhenAvailable?.asString()?.startsWith("kotlin.reflect.KFunction") == true) &&
|
||||
(callTarget.parentClassOrNull?.fqNameWhenAvailable?.asString()?.startsWith("kotlin.Function") == true)
|
||||
) {
|
||||
return receiverType.arguments
|
||||
}
|
||||
|
||||
// Populate ancestorTypes with the path from receiverType's class to its ancestor, callTarget's declaring type.
|
||||
fun walkFrom(c: IrClass): Boolean {
|
||||
if(declaringType == c)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Kotlin application project to get you started.
|
||||
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
|
||||
* User Manual available at https://docs.gradle.org/7.0.2/userguide/building_java_projects.html
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.6.20'
|
||||
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
id 'application'
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'testProject.AppKt'
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import kotlin.reflect.*
|
||||
|
||||
fun fn() {
|
||||
val ref: KFunction2<Ccc, Int, Double> = Ccc::m
|
||||
ref.invoke(Ccc(), 1)
|
||||
}
|
||||
|
||||
class Ccc {
|
||||
fun m(i:Int):Double = 5.0
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import java
|
||||
import semmle.code.java.Diagnostics
|
||||
|
||||
query predicate diag(Diagnostic d) { any() }
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/7.0.2/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = 'testProject'
|
||||
include('app')
|
||||
@@ -0,0 +1,5 @@
|
||||
from create_database_utils import *
|
||||
|
||||
run_codeql_database_create(
|
||||
["gradle build --no-daemon --no-build-cache --rerun-tasks"], lang="java")
|
||||
runSuccessfully(["gradle", "clean"])
|
||||
Reference in New Issue
Block a user