@@ -6,6 +6,7 @@ import com.github.codeql.utils.versions.functionN
6
6
import com.github.codeql.utils.versions.isUnderscoreParameter
7
7
import com.semmle.extractor.java.OdasaOutput
8
8
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
9
+ import org.jetbrains.kotlin.backend.common.ir.allOverridden
9
10
import org.jetbrains.kotlin.backend.common.lower.parents
10
11
import org.jetbrains.kotlin.backend.common.pop
11
12
import org.jetbrains.kotlin.builtins.functions.BuiltInFunctionArity
@@ -1855,16 +1856,27 @@ open class KotlinFileExtractor(
1855
1856
// Ensure the real target gets extracted, as we might not every directly touch it thanks to this call being redirected to a $default method.
1856
1857
useFunction<DbCallable >(callTarget)
1857
1858
}
1858
- val defaultMethodLabel = getDefaultsMethodLabel(callTarget)
1859
+
1860
+ // Default parameter values are inherited by overrides; in this case the call should dispatch against the $default method belonging to the class
1861
+ // that specified the default values, which will in turn dynamically dispatch back to the relevant override.
1862
+ val overriddenCallTarget = (callTarget as ? IrSimpleFunction )?.allOverridden(true )?.firstOrNull {
1863
+ it.overriddenSymbols.isEmpty() && it.valueParameters.any { p -> p.defaultValue != null }
1864
+ } ? : callTarget
1865
+ if (isExternalDeclaration(overriddenCallTarget)) {
1866
+ // Likewise, ensure the overridden target gets extracted.
1867
+ useFunction<DbCallable >(overriddenCallTarget)
1868
+ }
1869
+
1870
+ val defaultMethodLabel = getDefaultsMethodLabel(overriddenCallTarget)
1859
1871
val id = extractMethodAccessWithoutArgs(resultType, locId, enclosingCallable, callsiteParent, childIdx, enclosingStmt, defaultMethodLabel)
1860
1872
1861
- if (callTarget .isLocalFunction()) {
1862
- extractTypeAccess(getLocallyVisibleFunctionLabels(callTarget ).type, locId, id, - 1 , enclosingCallable, enclosingStmt)
1873
+ if (overriddenCallTarget .isLocalFunction()) {
1874
+ extractTypeAccess(getLocallyVisibleFunctionLabels(overriddenCallTarget ).type, locId, id, - 1 , enclosingCallable, enclosingStmt)
1863
1875
} else {
1864
- extractStaticTypeAccessQualifierUnchecked(callTarget .parent, id, locId, enclosingCallable, enclosingStmt)
1876
+ extractStaticTypeAccessQualifierUnchecked(overriddenCallTarget .parent, id, locId, enclosingCallable, enclosingStmt)
1865
1877
}
1866
1878
1867
- extractDefaultsCallArguments(id, callTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1879
+ extractDefaultsCallArguments(id, overriddenCallTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1868
1880
}
1869
1881
1870
1882
private fun extractDefaultsCallArguments (
0 commit comments