diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..03e22d69f1b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{kt,kts}] +indent_style = space +indent_size = 2 diff --git a/README.md b/README.md index 6aff87cb6e5..43dc48ecbb9 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Builds of the Gradle plugin are available through the ```kotlin plugins { - kotlin("jvm") version "1.4.0" + kotlin("jvm") version "1.4.20" id("com.bnorm.power.kotlin-power-assert") version "0.5.3" } ``` @@ -94,7 +94,7 @@ configure { ## Kotlin IR Using this compiler plugin only works if the code is compiled using Kotlin -1.4.0 and IR is enabled. This includes all IR based compiler backends: JVM, JS, +1.4.20 and IR is enabled. This includes all IR based compiler backends: JVM, JS, and Native! As Kotlin IR is still experimental, mileage may vary. ##### Kotlin/JVM diff --git a/build.gradle.kts b/build.gradle.kts index 7d45bbc7d83..cedc954ae92 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") version "1.4.0" apply false + kotlin("jvm") version "1.4.20" apply false id("org.jetbrains.dokka") version "0.10.0" apply false id("com.gradle.plugin-publish") version "0.11.0" apply false id("com.github.gmazzo.buildconfig") version "2.0.2" apply false diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/IrStackVariable.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/IrStackVariable.kt index 6ef3aa0c5dc..faa5b9abb5a 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/IrStackVariable.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/IrStackVariable.kt @@ -16,6 +16,7 @@ package com.bnorm.power +import org.jetbrains.kotlin.backend.common.ir.isSuspend import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope @@ -23,10 +24,13 @@ import org.jetbrains.kotlin.ir.builders.irConcat import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.builders.irString import org.jetbrains.kotlin.ir.declarations.IrFile +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol data class IrStackVariable( val temporary: IrVariable, @@ -62,11 +66,10 @@ fun IrBuilderWithScope.buildMessage( var row = info.startLineNumber - originalInfo.startLineNumber val columnOffset: Int = when (original) { - is IrMemberAccessExpression -> { - // TODO IrFunction doesn't have 'isInfix' as a property - val descriptor = original.symbol.descriptor + is IrMemberAccessExpression<*> -> { + val owner = original.symbol.owner when { - descriptor is FunctionDescriptor && descriptor.isInfix -> source.indexOf(descriptor.name.asString()) + owner is IrSimpleFunction && owner.isInfix -> source.indexOf(owner.name.asString()) else -> when (original.origin) { // TODO handle equality and comparison better? IrStatementOrigin.EQEQ, IrStatementOrigin.EQEQEQ -> source.indexOf("==") diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt index 14bd6fd876d..54d3134a460 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.backend.common.ir.inline import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.backend.common.lower.at import org.jetbrains.kotlin.cli.common.messages.* -import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.declarations.buildFun @@ -48,9 +47,9 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.util.OperatorNameConventions import java.io.File +import org.jetbrains.kotlin.descriptors.DescriptorVisibilities fun FileLoweringPass.runOnFileInOrder(irFile: IrFile) { irFile.acceptVoid(object : IrElementVisitorVoid { @@ -81,8 +80,7 @@ class PowerAssertCallTransformer( } override fun visitCall(expression: IrCall): IrExpression { - // TODO expression.symbol.owner.fqNameSafe includes the wrapping ClassKt while descriptor doesn't - val fqName = expression.symbol.descriptor.fqNameSafe + val fqName = expression.symbol.owner.kotlinFqName if (functions.none { fqName == it }) return super.visitCall(expression) @@ -179,10 +177,10 @@ class PowerAssertCallTransformer( object : FunctionDelegate { override fun buildCall(builder: IrBuilderWithScope, original: IrCall, message: IrExpression): IrExpression = with(builder) { val scope = this - val lambda = buildFun { + val lambda = builder.context.irFactory.buildFun { name = Name.special("") returnType = context.irBuiltIns.stringType - visibility = Visibilities.LOCAL + visibility = DescriptorVisibilities.LOCAL origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA }.apply { val bodyBuilder = DeclarationIrBuilder(this@PowerAssertCallTransformer.context, symbol) diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/internal/ReturnableBlockTransformer.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/internal/ReturnableBlockTransformer.kt index 13f85e47e20..f5df2377e6e 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/internal/ReturnableBlockTransformer.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/internal/ReturnableBlockTransformer.kt @@ -2,7 +2,7 @@ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * - * Copied from https://github.com/JetBrains/kotlin/blob/1.4.0/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt + * Copied from https://github.com/JetBrains/kotlin/blob/1.4.20/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt */ package com.bnorm.power.internal @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.transformStatement // TODO Remove when inlining works correctly on Kotlin/JS and Kotlin/Native class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerSymbol: IrSymbol? = null) : IrElementTransformerVoidWithContext() { @@ -52,7 +53,7 @@ class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerS returnMap[expression.symbol] = { returnExpression -> hasReturned = true builder.irComposite(returnExpression) { - +irSetVar(variable.symbol, returnExpression.value) + +irSet(variable.symbol, returnExpression.value) +irBreak(loop) } } @@ -61,10 +62,10 @@ class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerS if (i == expression.statements.lastIndex && s is IrReturn && s.returnTargetSymbol == expression.symbol) { s.transformChildrenVoid() if (!hasReturned) s.value else { - builder.irSetVar(variable.symbol, s.value) + builder.irSet(variable.symbol, s.value) } } else { - s.transform(this, null) + s.transformStatement(this) } } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 6eea9635b6a..a3c4713b169 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") version "1.4.0" + kotlin("multiplatform") version "1.4.20" id("com.bnorm.power.kotlin-power-assert") version "0.5.3" }