From 004f4be5fb43ad3ef9dc427c6deb6ecdca2fa3ed Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 25 Oct 2022 17:09:05 +0100 Subject: [PATCH] Kotlin: don't try to call nonexistent `j.l.Number.toChar` Previously we thought this could be callable because Kotlin's view of `j.l.Integer` inherits `k.Number` which defines `toChar`. --- java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt | 1 + .../call-int-to-char/CONSISTENCY/javaEquivalent.expected | 1 + .../test/kotlin/library-tests/call-int-to-char/test.expected | 1 + java/ql/test/kotlin/library-tests/call-int-to-char/test.kt | 1 + java/ql/test/kotlin/library-tests/call-int-to-char/test.ql | 4 ++++ 5 files changed, 8 insertions(+) create mode 100644 java/ql/test/kotlin/library-tests/call-int-to-char/CONSISTENCY/javaEquivalent.expected create mode 100644 java/ql/test/kotlin/library-tests/call-int-to-char/test.expected create mode 100644 java/ql/test/kotlin/library-tests/call-int-to-char/test.kt create mode 100644 java/ql/test/kotlin/library-tests/call-int-to-char/test.ql diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt index fd9ec136104..613c973f3c3 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt @@ -1281,6 +1281,7 @@ open class KotlinUsesExtractor( } // Look for an exact type match... javaClass.declarations.findSubType { decl -> + !decl.isFakeOverride && decl.name.asString() == jvmName && decl.valueParameters.size == f.valueParameters.size && decl.valueParameters.zip(f.valueParameters).all { p -> erase(p.first.type).classifierOrNull == erase(p.second.type).classifierOrNull } diff --git a/java/ql/test/kotlin/library-tests/call-int-to-char/CONSISTENCY/javaEquivalent.expected b/java/ql/test/kotlin/library-tests/call-int-to-char/CONSISTENCY/javaEquivalent.expected new file mode 100644 index 00000000000..02fc2a94b39 --- /dev/null +++ b/java/ql/test/kotlin/library-tests/call-int-to-char/CONSISTENCY/javaEquivalent.expected @@ -0,0 +1 @@ +| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.toChar in java.lang.Integer | diff --git a/java/ql/test/kotlin/library-tests/call-int-to-char/test.expected b/java/ql/test/kotlin/library-tests/call-int-to-char/test.expected new file mode 100644 index 00000000000..c3ee02d7bd6 --- /dev/null +++ b/java/ql/test/kotlin/library-tests/call-int-to-char/test.expected @@ -0,0 +1 @@ +| test.kt:1:19:1:26 | toChar(...) | diff --git a/java/ql/test/kotlin/library-tests/call-int-to-char/test.kt b/java/ql/test/kotlin/library-tests/call-int-to-char/test.kt new file mode 100644 index 00000000000..d602aeb0992 --- /dev/null +++ b/java/ql/test/kotlin/library-tests/call-int-to-char/test.kt @@ -0,0 +1 @@ +fun f(x: Int) = x.toChar() diff --git a/java/ql/test/kotlin/library-tests/call-int-to-char/test.ql b/java/ql/test/kotlin/library-tests/call-int-to-char/test.ql new file mode 100644 index 00000000000..ab60ba2525d --- /dev/null +++ b/java/ql/test/kotlin/library-tests/call-int-to-char/test.ql @@ -0,0 +1,4 @@ +import java + +from MethodAccess ma +select ma