[FIR] remove user code leaks from compiler.fir.raw-fir module, add more information to some errors
This commit is contained in:
committed by
Space Team
parent
d43057e19a
commit
9f847da13e
+15
-8
@@ -50,6 +50,9 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||
|
||||
open class PsiRawFirBuilder(
|
||||
session: FirSession,
|
||||
@@ -1117,17 +1120,19 @@ open class PsiRawFirBuilder(
|
||||
for (declaration in file.declarations) {
|
||||
declarations += when (declaration) {
|
||||
is KtScript -> {
|
||||
require(file.declarations.size == 1) { "Expect the script to be the only declaration in the file $name" }
|
||||
convertScript(declaration, this.name) {
|
||||
for (configurator in baseSession.extensionService.scriptConfigurators) {
|
||||
with(configurator) { configure(this@buildFile) }
|
||||
}
|
||||
requireWithAttachment(file.declarations.size == 1, message = { "Expect the script to be the only declaration in the file" }) {
|
||||
withEntry("fileName", file.name)
|
||||
}
|
||||
convertScript(declaration, this.name) {
|
||||
for (configurator in baseSession.extensionService.scriptConfigurators) {
|
||||
with(configurator) { configure(this@buildFile) }
|
||||
}
|
||||
}
|
||||
is KtDestructuringDeclaration -> buildErrorTopLevelDestructuringDeclaration(declaration.toFirSourceElement())
|
||||
else -> declaration.convert()
|
||||
}
|
||||
is KtDestructuringDeclaration -> buildErrorTopLevelDestructuringDeclaration(declaration.toFirSourceElement())
|
||||
else -> declaration.convert()
|
||||
}
|
||||
}
|
||||
|
||||
for (danglingModifierList in file.danglingModifierLists) {
|
||||
declarations += buildErrorTopLevelDeclarationForDanglingModifierList(danglingModifierList)
|
||||
@@ -2262,7 +2267,9 @@ open class PsiRawFirBuilder(
|
||||
is KtEscapeStringTemplateEntry -> KtNodeTypes.ESCAPE_STRING_TEMPLATE_ENTRY
|
||||
is KtSimpleNameStringTemplateEntry -> KtNodeTypes.SHORT_STRING_TEMPLATE_ENTRY
|
||||
is KtBlockStringTemplateEntry -> KtNodeTypes.LONG_STRING_TEMPLATE_ENTRY
|
||||
else -> error("invalid node type $element")
|
||||
else -> errorWithAttachment("invalid node type ${element::class.java}") {
|
||||
withPsiEntry("element", element)
|
||||
}
|
||||
}
|
||||
},
|
||||
convertTemplateEntry = {
|
||||
|
||||
+15
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.builder
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
@@ -38,6 +39,9 @@ import org.jetbrains.kotlin.parsing.*
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.exceptions.ExceptionAttachmentBuilder
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||
|
||||
//T can be either PsiElement, or LighterASTNode
|
||||
abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context: Context<T> = Context()) {
|
||||
@@ -417,10 +421,20 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
||||
setType = false
|
||||
)
|
||||
else ->
|
||||
throw AssertionError("Unknown literal type: $type, $text")
|
||||
errorWithAttachment("Unknown literal type: $type") {
|
||||
withSourceElementEntry("literal", expression)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun ExceptionAttachmentBuilder.withSourceElementEntry(name: String, element: T?) {
|
||||
when (element) {
|
||||
is PsiElement -> withPsiEntry(name, element)
|
||||
else -> withEntry(name, element) { it.asText}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(
|
||||
source: T,
|
||||
receiver: FirExpression,
|
||||
|
||||
Reference in New Issue
Block a user