[JS IR] Verify that we don't generate Unit_getInstance() statements
See: KT-51127
This commit is contained in:
@@ -6,12 +6,10 @@
|
||||
package org.jetbrains.kotlin.js.test.handlers
|
||||
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpressionStatement
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNullLiteral
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
||||
import org.jetbrains.kotlin.js.backend.ast.RecursiveJsVisitor
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.facade.TranslationResult
|
||||
import org.jetbrains.kotlin.js.testOld.utils.DirectiveTestUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.name
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.backend.handlers.JsBinaryArtifactHandler
|
||||
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
||||
@@ -35,21 +33,26 @@ class JsAstHandler(testServices: TestServices) : JsBinaryArtifactHandler(testSer
|
||||
|
||||
private fun processJsProgram(program: JsProgram, psiFiles: List<String>, targetBackend: TargetBackend) {
|
||||
psiFiles.forEach { DirectiveTestUtils.processDirectives(program, it, targetBackend) }
|
||||
|
||||
// TODO: For now the IR backend generates JS code that doesn't pass verification,
|
||||
// TODO: so we temporarily disabled AST verification.
|
||||
if (targetBackend == TargetBackend.JS) {
|
||||
program.verifyAst()
|
||||
}
|
||||
program.verifyAst(targetBackend)
|
||||
}
|
||||
|
||||
private fun JsProgram.verifyAst() {
|
||||
private fun JsProgram.verifyAst(targetBackend: TargetBackend) {
|
||||
accept(object : RecursiveJsVisitor() {
|
||||
override fun visitExpressionStatement(x: JsExpressionStatement) {
|
||||
when (x.expression) {
|
||||
is JsNullLiteral -> testServices.assertions.fail { "Expression statement contains `null` literal" }
|
||||
else -> super.visitExpressionStatement(x)
|
||||
val expression = x.expression
|
||||
|
||||
// FIXME: The code generated by the IR BE contains null statements. Remove this check when that is fixed.
|
||||
if (targetBackend == TargetBackend.JS) {
|
||||
if (expression is JsNullLiteral) {
|
||||
testServices.assertions.fail { "Expression statement contains `null` literal" }
|
||||
}
|
||||
}
|
||||
|
||||
if (expression is JsInvocation && expression.name?.ident == "Unit_getInstance" && expression.arguments.isEmpty()) {
|
||||
testServices.assertions.fail { "Unit_getInstance() statements should be eliminated" }
|
||||
}
|
||||
|
||||
super.visitExpressionStatement(x)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user