Skip to content

Commit 8a5bc3b

Browse files
committed
Kotlin: Don't use hasQuestionMark
1.7.0 warns: 'hasQuestionMark: Boolean' is deprecated. hasQuestionMark has ambiguous meaning. Use isNullable() or isMarkedNullable() instead
1 parent fce111b commit 8a5bc3b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ open class KotlinFileExtractor(
16941694
result
16951695
}
16961696

1697-
private fun isFunction(target: IrFunction, pkgName: String, classNameLogged: String, classNamePredicate: (String) -> Boolean, fName: String, hasQuestionMark: Boolean? = false): Boolean {
1697+
private fun isFunction(target: IrFunction, pkgName: String, classNameLogged: String, classNamePredicate: (String) -> Boolean, fName: String, isNullable: Boolean? = false): Boolean {
16981698
val verbose = false
16991699
fun verboseln(s: String) { if(verbose) println(s) }
17001700
verboseln("Attempting match for $pkgName $classNameLogged $fName")
@@ -1704,14 +1704,14 @@ open class KotlinFileExtractor(
17041704
}
17051705
val extensionReceiverParameter = target.extensionReceiverParameter
17061706
val targetClass = if (extensionReceiverParameter == null) {
1707-
if (hasQuestionMark == true) {
1707+
if (isNullable == true) {
17081708
verboseln("Nullablility of type didn't match (target is not an extension method)")
17091709
return false
17101710
}
17111711
target.parent
17121712
} else {
17131713
val st = extensionReceiverParameter.type as? IrSimpleType
1714-
if (hasQuestionMark != null && st?.hasQuestionMark != hasQuestionMark) {
1714+
if (isNullable != null && st?.isNullable() != isNullable) {
17151715
verboseln("Nullablility of type didn't match")
17161716
return false
17171717
}
@@ -1738,8 +1738,8 @@ open class KotlinFileExtractor(
17381738
return true
17391739
}
17401740

1741-
private fun isFunction(target: IrFunction, pkgName: String, className: String, fName: String, hasQuestionMark: Boolean? = false) =
1742-
isFunction(target, pkgName, className, { it == className }, fName, hasQuestionMark)
1741+
private fun isFunction(target: IrFunction, pkgName: String, className: String, fName: String, isNullable: Boolean? = false) =
1742+
isFunction(target, pkgName, className, { it == className }, fName, isNullable)
17431743

17441744
private fun isNumericFunction(target: IrFunction, fName: String): Boolean {
17451745
return isFunction(target, "kotlin", "Int", fName) ||

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ open class KotlinUsesExtractor(
650650
otherIsPrimitive: Boolean,
651651
javaClass: IrClass,
652652
kotlinPackageName: String, kotlinClassName: String): TypeResults {
653-
val javaResult = if ((context == TypeContext.RETURN || (context == TypeContext.OTHER && otherIsPrimitive)) && !s.hasQuestionMark && primitiveName != null) {
653+
val javaResult = if ((context == TypeContext.RETURN || (context == TypeContext.OTHER && otherIsPrimitive)) && !s.isNullable() && primitiveName != null) {
654654
val label: Label<DbPrimitive> = tw.getLabelFor("@\"type;$primitiveName\"", {
655655
tw.writePrimitives(it, primitiveName)
656656
})
@@ -660,7 +660,7 @@ open class KotlinUsesExtractor(
660660
}
661661
val kotlinClassId = useClassInstance(kotlinClass, listOf()).typeResult.id
662662
val kotlinResult = if (true) TypeResult(fakeKotlinType(), "TODO", "TODO") else
663-
if (s.hasQuestionMark) {
663+
if (s.isNullable()) {
664664
val kotlinSignature = "$kotlinPackageName.$kotlinClassName?" // TODO: Is this right?
665665
val kotlinLabel = "@\"kt_type;nullable;$kotlinPackageName.$kotlinClassName\""
666666
val kotlinId: Label<DbKt_nullable_type> = tw.getLabelFor(kotlinLabel, {
@@ -704,13 +704,13 @@ open class KotlinUsesExtractor(
704704
owner is IrClass -> {
705705
val args = if (s.isRawType()) null else s.arguments
706706

707-
return useSimpleTypeClass(owner, args, s.hasQuestionMark)
707+
return useSimpleTypeClass(owner, args, s.isNullable())
708708
}
709709
owner is IrTypeParameter -> {
710710
val javaResult = useTypeParameter(owner)
711711
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
712712
val kotlinResult = if (true) TypeResult(fakeKotlinType(), "TODO", "TODO") else
713-
if (s.hasQuestionMark) {
713+
if (s.isNullable()) {
714714
val kotlinSignature = "${javaResult.signature}?" // TODO: Wrong
715715
val kotlinLabel = "@\"kt_type;nullable;type_param\"" // TODO: Wrong
716716
val kotlinId: Label<DbKt_nullable_type> = tw.getLabelFor(kotlinLabel, {
@@ -1485,7 +1485,7 @@ open class KotlinUsesExtractor(
14851485
if (t.isArray() || t.isNullableArray()) {
14861486
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
14871487
val erasedElementType = erase(elementType)
1488-
return owner.typeWith(erasedElementType).codeQlWithHasQuestionMark(t.hasQuestionMark)
1488+
return owner.typeWith(erasedElementType).codeQlWithHasQuestionMark(t.isNullable())
14891489
}
14901490

14911491
return if (t.arguments.isNotEmpty())

java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private fun IrSimpleType.substituteTypeArguments(substitutionMap: Map<IrTypePara
5656

5757
return IrSimpleTypeImpl(
5858
classifier,
59-
hasQuestionMark,
59+
isNullable(),
6060
newArguments,
6161
annotations
6262
)
@@ -92,7 +92,7 @@ private fun subProjectedType(substitutionMap: Map<IrTypeParameterSymbol, IrTypeA
9292
if (conflictingVariance(outerVariance, substitutedTypeArg.variance))
9393
IrStarProjectionImpl
9494
else {
95-
val newProjectedType = substitutedTypeArg.type.let { if (t.hasQuestionMark) it.codeQlWithHasQuestionMark(true) else it }
95+
val newProjectedType = substitutedTypeArg.type.let { if (t.isNullable()) it.codeQlWithHasQuestionMark(true) else it }
9696
val newVariance = combineVariance(outerVariance, substitutedTypeArg.variance)
9797
makeTypeProjection(newProjectedType, newVariance)
9898
}
@@ -196,7 +196,7 @@ fun IrTypeArgument.withQuestionMark(b: Boolean): IrTypeArgument =
196196
is IrStarProjection -> this
197197
is IrTypeProjection ->
198198
this.type.let { when(it) {
199-
is IrSimpleType -> if (it.hasQuestionMark == b) this else makeTypeProjection(it.codeQlWithHasQuestionMark(b), this.variance)
199+
is IrSimpleType -> if (it.isNullable() == b) this else makeTypeProjection(it.codeQlWithHasQuestionMark(b), this.variance)
200200
else -> this
201201
}}
202202
else -> this

0 commit comments

Comments
 (0)