I need to run static analysis on source jars conta...
# compiler
s
I need to run static analysis on source jars containing Kotlin files with full name resolution. Im using K2JVMCompiler from kotlin-compiler-embeddable along with my analysis compiler plugin for this task. Classpath for an artifact is resolved using Coursier. Currently, Im attempting to analyze
org.jetbrains.kotlin:kotlin-stdlib:1.5.21
, but Im getting a lot of errors about
/tmp/kotlin-stdlib/kotlin/util/Synchronized.kt:16:18: error: cannot access 'InlineOnly': it is internal in 'kotlin.internal'
in the files that use these internal symbols.
Having fixed the first error, Im still left with a host of
/tmp/kotlin-stdlib/kotlin/util/NumbersJVM.kt:185:31: error: actual function 'countLeadingZeroBits' has no corresponding expected declaration
and the same for other symbols. The args to K2JVMCompiler are as follows:
Copy code
-Xplugin=/home/noah/Sourcegraph/lsif-kotlin/semanticdb-kotlinc-1.0-SNAPSHOT.jar -P plugin:com.sourcegraph.lsif-kotlin:sourceroot=/tmp/kotlin-stdlib -P plugin:com.sourcegraph.lsif-kotlin:targetroot=/tmp/kotlin-stdlib/target -no-reflect -no-stdlib -Xno-check-actual -Xopt-in=kotlin.RequiresOptIn -Xopt-in=kotlin.ExperimentalUnsignedTypes -Xopt-in=kotlin.ExperimentalStdlibApi -Xopt-in=kotlin.contracts.ExperimentalContracts -Xopt-in=kotlin.ExperimentalMultiplatform -Xallow-kotlin-package -Xmulti-platform -nowarn -classpath /home/noah/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.5.21/kotlin-stdlib-1.5.21.jar:/home/noah/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/annotations/13.0/annotations-13.0.jar:/home/noah/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.5.21/kotlin-stdlib-common-1.5.21.jar
Anyone any ideas?
y
I think you need to include both the sources for the stdlib and also the sources for the stdlib common because the issue you're getting is cuz it's not recognising the base
expect
declaration that you're overriding iwith
actual
Yeah the Kotlin sources have a tendency to leave some functions kind of up-for-grabs because they're actually implemented depending on the platform. So I'd say probably just suppress those errors (I think through messing with
MutableDiagnostics
but I can't quite remember). @raulraja I think might be helpful in here cuz Arrow Meta did have some diagnostic-suppression logic in it
👍 1
r
Mutable diagnostic are part of the BindingTrace which you can get a hold of with a compiler plugin in the analysis extension handler. You may have to cast the diagnostics. Not sure if there is a better way to suppress them.
😞 1
s
I've resorted to providing a custom MessageCollector. Not quite the elegant solution I was hoping for, but it "works". If theres any other suggestions on how I could keep the compiler happy in this case, Im all ears 🙂 thx for the help so far everyone