@@ -2,6 +2,7 @@ package com.github.codeql
22
33import com.github.codeql.comments.CommentExtractor
44import com.github.codeql.utils.*
5+ import com.github.codeql.utils.versions.allOverriddenIncludingSelf
56import com.github.codeql.utils.versions.functionN
67import com.github.codeql.utils.versions.isUnderscoreParameter
78import com.semmle.extractor.java.OdasaOutput
@@ -1847,16 +1848,27 @@ open class KotlinFileExtractor(
18471848 // Ensure the real target gets extracted, as we might not every directly touch it thanks to this call being redirected to a $default method.
18481849 useFunction<DbCallable >(callTarget)
18491850 }
1850- val defaultMethodLabel = getDefaultsMethodLabel(callTarget)
1851+
1852+ // Default parameter values are inherited by overrides; in this case the call should dispatch against the $default method belonging to the class
1853+ // that specified the default values, which will in turn dynamically dispatch back to the relevant override.
1854+ val overriddenCallTarget = (callTarget as ? IrSimpleFunction )?.allOverriddenIncludingSelf()?.firstOrNull {
1855+ it.overriddenSymbols.isEmpty() && it.valueParameters.any { p -> p.defaultValue != null }
1856+ } ? : callTarget
1857+ if (isExternalDeclaration(overriddenCallTarget)) {
1858+ // Likewise, ensure the overridden target gets extracted.
1859+ useFunction<DbCallable >(overriddenCallTarget)
1860+ }
1861+
1862+ val defaultMethodLabel = getDefaultsMethodLabel(overriddenCallTarget)
18511863 val id = extractMethodAccessWithoutArgs(resultType, locId, enclosingCallable, callsiteParent, childIdx, enclosingStmt, defaultMethodLabel)
18521864
1853- if (callTarget .isLocalFunction()) {
1854- extractTypeAccess(getLocallyVisibleFunctionLabels(callTarget ).type, locId, id, - 1 , enclosingCallable, enclosingStmt)
1865+ if (overriddenCallTarget .isLocalFunction()) {
1866+ extractTypeAccess(getLocallyVisibleFunctionLabels(overriddenCallTarget ).type, locId, id, - 1 , enclosingCallable, enclosingStmt)
18551867 } else {
1856- extractStaticTypeAccessQualifierUnchecked(callTarget .parent, id, locId, enclosingCallable, enclosingStmt)
1868+ extractStaticTypeAccessQualifierUnchecked(overriddenCallTarget .parent, id, locId, enclosingCallable, enclosingStmt)
18571869 }
18581870
1859- extractDefaultsCallArguments(id, callTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1871+ extractDefaultsCallArguments(id, overriddenCallTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
18601872 }
18611873
18621874 private fun extractDefaultsCallArguments (
0 commit comments