Kotlin: Give context to diagnostics

We now get e.g.

[2022-03-09 13:59:04 K] [ERROR] Diagnostic(com.github.codeql.KotlinUsesExtractor.useSimpleType(KotlinUsesExtractor.kt:505)): Type alias ignored for <root>.Test<kotlin.String>{ <root>.Alias1<kotlin.String> }
  ...while extracting a function at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a function if real at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a declaration at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:7:1:7:41
  ...while extracting a file at file:///home/ian/code/dev/ql/java/ql/test/kotlin/library-tests/type_aliases/aliases_with_type_parameters.kt:1:1:8:0
This commit is contained in:
Ian Lynagh
2022-03-09 14:00:32 +00:00
parent a7e6ec9d02
commit 43a92f60b2
3 changed files with 22 additions and 9 deletions

View File

@@ -9,7 +9,6 @@ import java.io.File
import java.io.FileOutputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Stack
import com.semmle.util.files.FileUtil
import kotlin.system.exitProcess
@@ -121,8 +120,6 @@ class KotlinExtractorExtension(
}
}
data class ExtractorContext(val kind: String, val element: IrElement)
class KotlinExtractorGlobalState {
val genericSpecialisationsExtracted = HashSet<String>()
// These three record mappings of classes, functions and fields that should be replaced wherever they are found.
@@ -132,8 +129,6 @@ class KotlinExtractorGlobalState {
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
// TODO: This could be less global; it's really per-file
val context = Stack<ExtractorContext>()
}
/*