[PL] Fix line/column numbers in error messages
This commit is contained in:
committed by
Space Team
parent
9a3eece944
commit
eec511a767
+12
-12
@@ -86,15 +86,15 @@ class WasmBackendContext(
|
||||
SourceRangeInfo(
|
||||
"",
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_LINE_NUMBER,
|
||||
UNDEFINED_COLUMN_NUMBER,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET
|
||||
UNDEFINED_LINE_NUMBER,
|
||||
UNDEFINED_COLUMN_NUMBER
|
||||
)
|
||||
|
||||
override fun getLineNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
override fun getColumnNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
override fun getLineNumber(offset: Int) = UNDEFINED_LINE_NUMBER
|
||||
override fun getColumnNumber(offset: Int) = UNDEFINED_COLUMN_NUMBER
|
||||
}, internalPackageFragmentDescriptor, irModuleFragment).also {
|
||||
irModuleFragment.files += it
|
||||
}
|
||||
@@ -158,15 +158,15 @@ class WasmBackendContext(
|
||||
SourceRangeInfo(
|
||||
"",
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_LINE_NUMBER,
|
||||
UNDEFINED_COLUMN_NUMBER,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET
|
||||
UNDEFINED_LINE_NUMBER,
|
||||
UNDEFINED_COLUMN_NUMBER
|
||||
)
|
||||
|
||||
override fun getLineNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
override fun getColumnNumber(offset: Int) = UNDEFINED_OFFSET
|
||||
override fun getLineNumber(offset: Int) = UNDEFINED_LINE_NUMBER
|
||||
override fun getColumnNumber(offset: Int) = UNDEFINED_COLUMN_NUMBER
|
||||
}, internalPackageFragmentDescriptor, module).also {
|
||||
module.files += it
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.ir
|
||||
|
||||
const val UNDEFINED_OFFSET: Int = -1
|
||||
const val UNDEFINED_LINE_NUMBER: Int = UNDEFINED_OFFSET
|
||||
const val UNDEFINED_COLUMN_NUMBER: Int = UNDEFINED_OFFSET
|
||||
|
||||
data class SourceRangeInfo(
|
||||
val filePath: String,
|
||||
|
||||
@@ -24,15 +24,15 @@ class PsiIrFileEntry(val psiFile: PsiFile) : IrFileEntry {
|
||||
}
|
||||
|
||||
override fun getLineNumber(offset: Int): Int {
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_LINE_NUMBER
|
||||
val index = lineStartOffsets.binarySearch(offset)
|
||||
return if (index >= 0) index else -index - 2
|
||||
}
|
||||
|
||||
override fun getColumnNumber(offset: Int): Int {
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
val lineNumber = getLineNumber(offset)
|
||||
if (lineNumber < 0) return -1
|
||||
if (lineNumber < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
return offset - lineStartOffsets[lineNumber]
|
||||
}
|
||||
|
||||
|
||||
@@ -227,15 +227,15 @@ class NaiveSourceBasedFileEntryImpl(
|
||||
|
||||
override fun getLineNumber(offset: Int): Int {
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_LINE_NUMBER
|
||||
return synchronized(lineNumberLock) { calculatedBeforeLineNumbers.get(offset) }
|
||||
}
|
||||
|
||||
override fun getColumnNumber(offset: Int): Int {
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
if (offset < 0) return -1
|
||||
if (offset < 0) return UNDEFINED_COLUMN_NUMBER
|
||||
val lineNumber = getLineNumber(offset)
|
||||
return if (lineNumber < 0) -1 else offset - lineStartOffsets[lineNumber]
|
||||
return if (lineNumber < 0) UNDEFINED_COLUMN_NUMBER else offset - lineStartOffsets[lineNumber]
|
||||
}
|
||||
|
||||
override fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo =
|
||||
|
||||
+36
-10
@@ -6,13 +6,12 @@
|
||||
package org.jetbrains.kotlin.backend.common.serialization.unlinked
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.PartialLinkageSupport.UnlinkedMarkerTypeHandler
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsProcessor.Companion.MISSING_ABSTRACT_CALLABLE_MEMBER_IMPLEMENTATION
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedIrElementRenderer.appendDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedIrElementRenderer.renderError
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UsedClassifierSymbolStatus.Companion.isUnlinked
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
@@ -348,12 +347,39 @@ private fun IrDeclaration.location(): Location? = locationIn(fileOrNull)
|
||||
private fun IrElement.locationIn(currentFile: IrFile?): Location? {
|
||||
if (currentFile == null) return null
|
||||
|
||||
val moduleName = currentFile.module.name
|
||||
val fileEntry = currentFile.fileEntry
|
||||
val fileName = fileEntry.name
|
||||
val lineNumber = fileEntry.getLineNumber(startOffset) + 1 // since humans count from 1, not 0
|
||||
val columnNumber = fileEntry.getColumnNumber(startOffset) + 1
|
||||
val moduleName: String = currentFile.module.name.asString()
|
||||
val filePath: String = currentFile.fileEntry.name
|
||||
|
||||
// unsure whether should module name be added here
|
||||
return Location("$moduleName @ $fileName", lineNumber, columnNumber)
|
||||
val lineNumber: Int
|
||||
val columnNumber: Int
|
||||
|
||||
when (val effectiveStartOffset = startOffsetOfFirstNonSyntheticIrElement()) {
|
||||
UNDEFINED_OFFSET -> {
|
||||
lineNumber = UNDEFINED_LINE_NUMBER
|
||||
columnNumber = UNDEFINED_COLUMN_NUMBER
|
||||
}
|
||||
else -> {
|
||||
lineNumber = currentFile.fileEntry.getLineNumber(effectiveStartOffset) + 1 // since humans count from 1, not 0
|
||||
columnNumber = currentFile.fileEntry.getColumnNumber(effectiveStartOffset) + 1
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: should module name still be added here?
|
||||
return Location("$moduleName @ $filePath", lineNumber, columnNumber)
|
||||
}
|
||||
|
||||
private tailrec fun IrElement.startOffsetOfFirstNonSyntheticIrElement(): Int = when (this) {
|
||||
is IrPackageFragment -> UNDEFINED_OFFSET
|
||||
!is IrDeclaration -> {
|
||||
// We don't generate synthetic IR expressions in the course of partial linkage.
|
||||
startOffset
|
||||
}
|
||||
else -> when (origin) {
|
||||
MISSING_ABSTRACT_CALLABLE_MEMBER_IMPLEMENTATION -> {
|
||||
// There is no sense to take coordinates from the declaration that does not exist in the code.
|
||||
// Let's take the coordinates of the parent.
|
||||
parent.startOffsetOfFirstNonSyntheticIrElement()
|
||||
}
|
||||
else -> startOffset
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user