Skip to content

Commit ca586b4

Browse files
committed
Merge remote-tracking branch 'upstream/main' into global
2 parents 0dd8f57 + c161bb5 commit ca586b4

File tree

163 files changed

+1453
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+1453
-449
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
libraryPathDependencies:
2-
- codeql-csharp
1+
dependencies:
2+
codeql/csharp-all: '*'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
name: legacy-libraries-go
22
version: 0.0.0
3+
# Note libraryPathDependencies is obsolete and should not be used in new qlpacks.
34
libraryPathDependencies: codeql-go

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ open class KotlinFileExtractor(
691691
null
692692
} ?: vp.type
693693
val javaType = (vp.parent as? IrFunction)?.let { getJavaCallable(it)?.let { jCallable -> getJavaValueParameterType(jCallable, idx) } }
694-
val typeWithWildcards = addJavaLoweringWildcards(maybeAlteredType, !hasWildcardSuppressionAnnotation(vp), javaType)
694+
val typeWithWildcards = addJavaLoweringWildcards(maybeAlteredType, !getInnermostWildcardSupppressionAnnotation(vp), javaType)
695695
val substitutedType = typeSubstitution?.let { it(typeWithWildcards, TypeContext.OTHER, pluginContext) } ?: typeWithWildcards
696696
val id = useValueParameter(vp, parent)
697697
if (extractTypeAccess) {
@@ -1188,22 +1188,16 @@ open class KotlinFileExtractor(
11881188
id
11891189

11901190
val extReceiver = f.extensionReceiverParameter
1191-
val idxOffset = if (extReceiver != null) 1 else 0
1192-
val fParameters = overriddenAttributes?.valueParameters ?: f.valueParameters
1191+
val fParameters = listOfNotNull(extReceiver) + (overriddenAttributes?.valueParameters ?: f.valueParameters)
11931192
val paramTypes = fParameters.mapIndexed { i, vp ->
1194-
extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, overriddenAttributes?.sourceLoc)
1193+
extractValueParameter(vp, id, i, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, overriddenAttributes?.sourceLoc)
11951194
}
1196-
val allParamTypes = if (extReceiver != null) {
1197-
val extendedType = useType(extReceiver.type)
1195+
if (extReceiver != null) {
1196+
val extendedType = paramTypes[0]
11981197
tw.writeKtExtensionFunctions(id.cast<DbMethod>(), extendedType.javaResult.id, extendedType.kotlinResult.id)
1199-
1200-
val t = extractValueParameter(extReceiver, id, 0, null, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractMethodAndParameterTypeAccesses, overriddenAttributes?.sourceLoc)
1201-
listOf(t) + paramTypes
1202-
} else {
1203-
paramTypes
12041198
}
12051199

1206-
val paramsSignature = allParamTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { signatureOrWarn(it.javaResult, f) }
1200+
val paramsSignature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { signatureOrWarn(it.javaResult, f) }
12071201

12081202
val adjustedReturnType = addJavaLoweringWildcards(getAdjustedReturnType(f), false, (javaCallable as? JavaMethod)?.returnType)
12091203
val substReturnType = typeSubstitution?.let { it(adjustedReturnType, TypeContext.RETURN, pluginContext) } ?: adjustedReturnType

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -964,17 +964,24 @@ open class KotlinUsesExtractor(
964964
when {
965965
t.hasAnnotation(jvmWildcardAnnotation) -> true
966966
!addByDefault -> false
967-
t.hasAnnotation(jvmWildcardSuppressionAnnotation) -> false
968967
// If a Java declaration specifies a variance, introduce it even if it's pointless (e.g. ? extends FinalClass, or ? super Object)
969968
javaVariance == v -> true
970969
v == Variance.IN_VARIANCE -> !(t.isNullableAny() || t.isAny())
971970
v == Variance.OUT_VARIANCE -> extendsAdditionAllowed(t)
972971
else -> false
973972
}
974973

974+
// Returns true if `t` has `@JvmSuppressWildcards` or `@JvmSuppressWildcards(true)`,
975+
// false if it has `@JvmSuppressWildcards(false)`,
976+
// and null if the annotation is not present.
977+
@Suppress("UNCHECKED_CAST")
978+
private fun getWildcardSuppressionDirective(t: IrAnnotationContainer) =
979+
t.getAnnotation(jvmWildcardSuppressionAnnotation)?.let { (it.getValueArgument(0) as? IrConst<Boolean>)?.value ?: true }
980+
975981
private fun addJavaLoweringArgumentWildcards(p: IrTypeParameter, t: IrTypeArgument, addByDefault: Boolean, javaType: JavaType?): IrTypeArgument =
976982
(t as? IrTypeProjection)?.let {
977-
val newBase = addJavaLoweringWildcards(it.type, addByDefault, javaType)
983+
val newAddByDefault = getWildcardSuppressionDirective(it.type)?.not() ?: addByDefault
984+
val newBase = addJavaLoweringWildcards(it.type, newAddByDefault, javaType)
978985
// Note javaVariance == null means we don't have a Java type to conform to -- for example if this is a Kotlin source definition.
979986
val javaVariance = javaType?.let { jType ->
980987
when (jType) {
@@ -989,7 +996,7 @@ open class KotlinUsesExtractor(
989996
// For example, Java might declare f(Comparable<CharSequence> cs), in which case we shouldn't add a `? super ...`
990997
// wildcard. Note if javaType is unknown (e.g. this is a Kotlin source element), we assume wildcards should be added.
991998
(javaVariance == null || javaVariance == p.variance) &&
992-
wildcardAdditionAllowed(p.variance, it.type, addByDefault, javaVariance))
999+
wildcardAdditionAllowed(p.variance, it.type, newAddByDefault, javaVariance))
9931000
p.variance
9941001
else
9951002
it.variance
@@ -1008,12 +1015,13 @@ open class KotlinUsesExtractor(
10081015

10091016
fun addJavaLoweringWildcards(t: IrType, addByDefault: Boolean, javaType: JavaType?): IrType =
10101017
(t as? IrSimpleType)?.let {
1018+
val newAddByDefault = getWildcardSuppressionDirective(t)?.not() ?: addByDefault
10111019
val typeParams = it.classOrNull?.owner?.typeParameters ?: return t
10121020
val newArgs = typeParams.zip(it.arguments).mapIndexed { idx, pair ->
10131021
addJavaLoweringArgumentWildcards(
10141022
pair.first,
10151023
pair.second,
1016-
addByDefault,
1024+
newAddByDefault,
10171025
javaType?.let { jt -> getJavaTypeArgument(jt, idx) }
10181026
)
10191027
}
@@ -1061,7 +1069,7 @@ open class KotlinUsesExtractor(
10611069
classTypeArgsIncludingOuterClasses,
10621070
overridesCollectionsMethodWithAlteredParameterTypes(f),
10631071
getJavaCallable(f),
1064-
!hasWildcardSuppressionAnnotation(f)
1072+
!getInnermostWildcardSupppressionAnnotation(f)
10651073
)
10661074

10671075
/*
@@ -1220,10 +1228,11 @@ open class KotlinUsesExtractor(
12201228
else -> null
12211229
}
12221230

1223-
fun hasWildcardSuppressionAnnotation(d: IrDeclaration) =
1224-
d.hasAnnotation(jvmWildcardSuppressionAnnotation) ||
1231+
fun getInnermostWildcardSupppressionAnnotation(d: IrDeclaration) =
1232+
getWildcardSuppressionDirective(d) ?:
12251233
// Note not using `parentsWithSelf` as that only works if `d` is an IrDeclarationParent
1226-
d.parents.any { (it as? IrAnnotationContainer)?.hasAnnotation(jvmWildcardSuppressionAnnotation) == true }
1234+
d.parents.filterIsInstance<IrAnnotationContainer>().mapNotNull { getWildcardSuppressionDirective(it) }.firstOrNull() ?:
1235+
false
12271236

12281237
/**
12291238
* Class to hold labels for generated classes around local functions, lambdas, function references, and property references.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: codeql-java-consistency-queries
22
version: 0.0.0
3-
libraryPathDependencies:
4-
- codeql-java
3+
dependencies:
4+
codeql/java-all: '*'

java/ql/integration-tests/posix-only/kotlin/enabling/build.py renamed to java/ql/integration-tests/all-platforms/kotlin/enabling/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from create_database_utils import *
44

5-
runSuccessfully(["kotlinc", "KotlinDefault.kt"])
5+
runSuccessfully([get_cmd("kotlinc"), "KotlinDefault.kt"])
66
os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN'] = 'true'
7-
runSuccessfully(["kotlinc", "KotlinDisabled.kt"])
7+
runSuccessfully([get_cmd("kotlinc"), "KotlinDisabled.kt"])
88
del(os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN'])
99
os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_ENABLE_KOTLIN'] = 'true'
10-
runSuccessfully(["kotlinc", "KotlinEnabled.kt"])
10+
runSuccessfully([get_cmd("kotlinc"), "KotlinEnabled.kt"])

0 commit comments

Comments
 (0)