@@ -2,6 +2,7 @@ package com.github.codeql
2
2
3
3
import com.github.codeql.comments.CommentExtractor
4
4
import com.github.codeql.utils.*
5
+ import com.github.codeql.utils.versions.allOverriddenIncludingSelf
5
6
import com.github.codeql.utils.versions.functionN
6
7
import com.github.codeql.utils.versions.isUnderscoreParameter
7
8
import com.semmle.extractor.java.OdasaOutput
@@ -1847,16 +1848,27 @@ open class KotlinFileExtractor(
1847
1848
// Ensure the real target gets extracted, as we might not every directly touch it thanks to this call being redirected to a $default method.
1848
1849
useFunction<DbCallable >(callTarget)
1849
1850
}
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)
1851
1863
val id = extractMethodAccessWithoutArgs(resultType, locId, enclosingCallable, callsiteParent, childIdx, enclosingStmt, defaultMethodLabel)
1852
1864
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)
1855
1867
} else {
1856
- extractStaticTypeAccessQualifierUnchecked(callTarget .parent, id, locId, enclosingCallable, enclosingStmt)
1868
+ extractStaticTypeAccessQualifierUnchecked(overriddenCallTarget .parent, id, locId, enclosingCallable, enclosingStmt)
1857
1869
}
1858
1870
1859
- extractDefaultsCallArguments(id, callTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1871
+ extractDefaultsCallArguments(id, overriddenCallTarget , enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1860
1872
}
1861
1873
1862
1874
private fun extractDefaultsCallArguments (
0 commit comments