Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit d8cb6b6

Browse files
authored
Merge pull request #9 from bnorm/bn/kotlin_1.3.70
Update to Kotlin 1.3.70
2 parents 7d4dc07 + 2ad1f1b commit d8cb6b6

File tree

9 files changed

+56
-63
lines changed

9 files changed

+56
-63
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "1.3.60" apply false
2+
kotlin("jvm") version "1.3.70" apply false
33
id("org.jetbrains.dokka") version "0.10.0" apply false
44
id("com.gradle.plugin-publish") version "0.10.1" apply false
55
}

kotlin-power-assert/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ plugins {
1111

1212
dependencies {
1313
implementation(kotlin("stdlib-jdk8"))
14-
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.60")
14+
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.70")
1515

1616
kapt("com.google.auto.service:auto-service:1.0-rc6")
1717
compileOnly("com.google.auto.service:auto-service-annotations:1.0-rc6")
1818

1919
testImplementation(kotlin("test-junit"))
20-
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.60")
21-
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.2.5")
20+
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.70")
21+
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.2.6")
2222
}
2323

2424
tasks.withType<KotlinCompile> {

kotlin-power-assert/src/main/kotlin/com/bnorm/power/AssertTree.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fun buildAssertTree(expression: IrExpression): RootNode {
101101
}
102102

103103
override fun visitCall(expression: IrCall, data: Node) {
104-
if (expression.descriptor.name.asString() == "EQEQ" && expression.origin == IrStatementOrigin.EXCLEQ) {
104+
if (expression.symbol.descriptor.name.asString() == "EQEQ" && expression.origin == IrStatementOrigin.EXCLEQ) {
105105
// Skip the EQEQ part of a EXCLEQ call
106106
expression.acceptChildren(this, data)
107107
} else {

kotlin-power-assert/src/main/kotlin/com/bnorm/power/IrStackVariable.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
package com.bnorm.power
1818

19-
import org.jetbrains.kotlin.backend.common.lower.irThrow
2019
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
2120
import org.jetbrains.kotlin.ir.IrElement
2221
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
23-
import org.jetbrains.kotlin.ir.builders.irCall
2422
import org.jetbrains.kotlin.ir.builders.irConcat
2523
import org.jetbrains.kotlin.ir.builders.irGet
2624
import org.jetbrains.kotlin.ir.builders.irString
@@ -29,8 +27,6 @@ import org.jetbrains.kotlin.ir.declarations.IrVariable
2927
import org.jetbrains.kotlin.ir.expressions.IrExpression
3028
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
3129
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
32-
import org.jetbrains.kotlin.ir.expressions.IrThrow
33-
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
3430

3531
data class IrStackVariable(
3632
val temporary: IrVariable,
@@ -44,13 +40,6 @@ data class ValueDisplay(
4440
val source: String
4541
)
4642

47-
fun IrBuilderWithScope.buildThrow(
48-
constructor: IrConstructorSymbol,
49-
message: IrExpression
50-
): IrThrow = irThrow(irCall(constructor).apply {
51-
putValueArgument(0, message)
52-
})
53-
5443
fun IrBuilderWithScope.buildMessage(
5544
file: IrFile,
5645
fileSource: String,
@@ -74,7 +63,7 @@ fun IrBuilderWithScope.buildMessage(
7463

7564
val columnOffset: Int = when (original) {
7665
is IrMemberAccessExpression -> {
77-
val descriptor = original.descriptor
66+
val descriptor = original.symbol.descriptor
7867
when {
7968
descriptor is FunctionDescriptor && descriptor.isInfix -> source.indexOf(descriptor.name.asString())
8069
else -> when (original.origin) {

kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
package com.bnorm.power
1818

19-
import org.jetbrains.kotlin.backend.common.BackendContext
2019
import org.jetbrains.kotlin.backend.common.FileLoweringPass
20+
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
21+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
2122
import org.jetbrains.kotlin.backend.common.ir.asSimpleLambda
2223
import org.jetbrains.kotlin.backend.common.ir.inline
24+
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
2325
import org.jetbrains.kotlin.backend.common.lower.at
24-
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
26+
import org.jetbrains.kotlin.backend.common.serialization.findPackage
2527
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
28+
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
2629
import org.jetbrains.kotlin.descriptors.Visibilities
2730
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
2831
import org.jetbrains.kotlin.ir.IrElement
@@ -36,7 +39,6 @@ import org.jetbrains.kotlin.ir.builders.irReturn
3639
import org.jetbrains.kotlin.ir.builders.irString
3740
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
3841
import org.jetbrains.kotlin.ir.declarations.IrFile
39-
import org.jetbrains.kotlin.ir.declarations.IrFunction
4042
import org.jetbrains.kotlin.ir.declarations.path
4143
import org.jetbrains.kotlin.ir.expressions.IrCall
4244
import org.jetbrains.kotlin.ir.expressions.IrConst
@@ -46,16 +48,14 @@ import org.jetbrains.kotlin.ir.expressions.IrStringConcatenation
4648
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionExpressionImpl
4749
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
4850
import org.jetbrains.kotlin.ir.types.getClass
49-
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
5051
import org.jetbrains.kotlin.ir.util.functions
51-
import org.jetbrains.kotlin.ir.util.getPackageFragment
5252
import org.jetbrains.kotlin.ir.util.referenceFunction
53-
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
5453
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
5554
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
5655
import org.jetbrains.kotlin.ir.visitors.acceptVoid
5756
import org.jetbrains.kotlin.name.FqName
5857
import org.jetbrains.kotlin.name.Name
58+
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
5959
import org.jetbrains.kotlin.types.KotlinType
6060
import org.jetbrains.kotlin.types.typeUtil.isBoolean
6161
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
@@ -76,9 +76,9 @@ fun FileLoweringPass.runOnFileInOrder(irFile: IrFile) {
7676
}
7777

7878
class PowerAssertCallTransformer(
79-
private val context: BackendContext,
79+
private val context: IrPluginContext,
8080
private val functions: Set<FqName>
81-
) : IrElementTransformerVoid(), FileLoweringPass {
81+
) : IrElementTransformerVoidWithContext(), FileLoweringPass {
8282
private lateinit var file: IrFile
8383
private lateinit var fileSource: String
8484

@@ -90,8 +90,8 @@ class PowerAssertCallTransformer(
9090
}
9191

9292
override fun visitCall(expression: IrCall): IrExpression {
93-
val function = expression.symbol.owner
94-
if (functions.none { function.fqNameWhenAvailable == it })
93+
val function = expression.symbol.descriptor
94+
if (functions.none { function.fqNameSafe == it })
9595
return super.visitCall(expression)
9696

9797
val delegate = findDelegate(function) ?: run {
@@ -103,24 +103,26 @@ class PowerAssertCallTransformer(
103103
val assertionArgument = expression.getValueArgument(0)!!
104104
val messageArgument = if (function.valueParameters.size == 2) expression.getValueArgument(1) else null
105105

106-
context.createIrBuilder(expression.symbol).run {
106+
val symbol = currentScope!!.scope.scopeOwnerSymbol
107+
DeclarationIrBuilder(context, symbol).run {
107108
at(expression)
108109

109-
val lambda = messageArgument?.asSimpleLambda()
110-
val title = when {
111-
messageArgument is IrConst<*> -> messageArgument
112-
messageArgument is IrStringConcatenation -> messageArgument
113-
lambda != null -> lambda.inline()
114-
messageArgument != null -> {
115-
val invoke = messageArgument.type.getClass()!!.functions.single { it.name == OperatorNameConventions.INVOKE }
116-
irCallOp(invoke.symbol, invoke.returnType, messageArgument)
117-
}
118-
// TODO what should the default message be?
119-
else -> irString("Assertion failed")
120-
}
121-
122110
val generator = object : PowerAssertGenerator() {
123111
override fun IrBuilderWithScope.buildAssertThrow(subStack: List<IrStackVariable>): IrExpression {
112+
113+
val lambda = messageArgument?.asSimpleLambda()
114+
val title = when {
115+
messageArgument is IrConst<*> -> messageArgument
116+
messageArgument is IrStringConcatenation -> messageArgument
117+
lambda != null -> lambda.inline()
118+
messageArgument != null -> {
119+
val invoke = messageArgument.type.getClass()!!.functions.single { it.name == OperatorNameConventions.INVOKE }
120+
irCallOp(invoke.symbol, invoke.returnType, messageArgument)
121+
}
122+
// TODO what should the default message be?
123+
else -> irString("Assertion failed")
124+
}
125+
124126
return delegate.buildCall(this, buildMessage(file, fileSource, title, expression, subStack))
125127
}
126128
}
@@ -140,7 +142,9 @@ class PowerAssertCallTransformer(
140142
fun buildCall(builder: IrBuilderWithScope, message: IrExpression): IrExpression
141143
}
142144

143-
private fun findDelegate(function: IrFunction): FunctionDelegate? {
145+
private fun findDelegate(function: FunctionDescriptor): FunctionDelegate? {
146+
fun KotlinType.toIrType() = context.typeTranslator.translateType(this)
147+
144148
return context.findOverloads(function)
145149
.mapNotNull { overload ->
146150
// TODO allow other signatures than (Boolean, String) and (Boolean, () -> String))
@@ -152,7 +156,7 @@ class PowerAssertCallTransformer(
152156
isStringSupertype(parameters[1].type) -> {
153157
object : FunctionDelegate {
154158
override fun buildCall(builder: IrBuilderWithScope, message: IrExpression): IrExpression = with(builder) {
155-
irCall(overload).apply {
159+
irCall(overload, type = overload.descriptor.returnType!!.toIrType()).apply {
156160
putValueArgument(0, irFalse())
157161
putValueArgument(1, message)
158162
}
@@ -168,13 +172,13 @@ class PowerAssertCallTransformer(
168172
visibility = Visibilities.LOCAL
169173
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
170174
}.apply {
171-
val bodyBuilder = this@PowerAssertCallTransformer.context.createIrBuilder(symbol)
175+
val bodyBuilder = DeclarationIrBuilder(this@PowerAssertCallTransformer.context, symbol)
172176
body = bodyBuilder.irBlockBody {
173177
+irReturn(message)
174178
}
175179
}
176180
val expression = IrFunctionExpressionImpl(-1, -1, context.irBuiltIns.stringType, lambda, IrStatementOrigin.LAMBDA)
177-
irCall(overload).apply {
181+
irCall(overload, type = overload.descriptor.returnType!!.toIrType()).apply {
178182
putValueArgument(0, irFalse())
179183
putValueArgument(1, expression)
180184
}
@@ -195,7 +199,7 @@ class PowerAssertCallTransformer(
195199
}
196200

197201
// TODO is this the best way to find overload functions?
198-
private fun BackendContext.findOverloads(function: IrFunction): List<IrFunctionSymbol> =
199-
function.getPackageFragment()!!.symbol.descriptor.getMemberScope()
202+
private fun IrPluginContext.findOverloads(function: FunctionDescriptor): List<IrFunctionSymbol> =
203+
function.findPackage().getMemberScope()
200204
.getContributedFunctions(function.name, NoLookupLocation.FROM_BACKEND)
201-
.map { ir.symbols.externalSymbolTable.referenceFunction(it) }
205+
.map { symbolTable.referenceFunction(it) }

kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616

1717
package com.bnorm.power
1818

19-
import org.jetbrains.kotlin.backend.common.BackendContext
2019
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
21-
import org.jetbrains.kotlin.ir.declarations.IrFile
20+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
21+
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
2222
import org.jetbrains.kotlin.name.FqName
23-
import org.jetbrains.kotlin.resolve.BindingContext
2423

2524
class PowerAssertIrGenerationExtension(
2625
private val functions: Set<FqName>
2726
) : IrGenerationExtension {
28-
override fun generate(file: IrFile, backendContext: BackendContext, bindingContext: BindingContext) {
29-
PowerAssertCallTransformer(backendContext, functions).runOnFileInOrder(file)
27+
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
28+
for (file in moduleFragment.files) {
29+
PowerAssertCallTransformer(pluginContext, functions).runOnFileInOrder(file)
30+
}
3031
}
3132
}

kotlin-power-assert/src/test/kotlin/com/bnorm/power/test.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ assertTrue(1 == 2, message = "${"$"}text, the world is broken")
345345
|
346346
false
347347
""".trimIndent(),
348-
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.AssertionsKt.assertTrue")))
348+
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue")))
349349
)
350350
}
351351

@@ -362,7 +362,7 @@ require(1 == 2) { "the world is broken" }
362362
|
363363
false
364364
""".trimIndent(),
365-
PowerAssertComponentRegistrar(setOf(FqName("kotlin.PreconditionsKt.require")))
365+
PowerAssertComponentRegistrar(setOf(FqName("kotlin.require")))
366366
)
367367
}
368368

@@ -379,15 +379,15 @@ check(1 == 2) { "the world is broken" }
379379
|
380380
false
381381
""".trimIndent(),
382-
PowerAssertComponentRegistrar(setOf(FqName("kotlin.PreconditionsKt.check")))
382+
PowerAssertComponentRegistrar(setOf(FqName("kotlin.check")))
383383
)
384384
}
385385
}
386386

387387
fun assertMessage(
388388
@Language("kotlin") source: String,
389389
message: String,
390-
vararg plugins: ComponentRegistrar = arrayOf(PowerAssertComponentRegistrar(setOf(FqName("kotlin.PreconditionsKt.assert"))))
390+
vararg plugins: ComponentRegistrar = arrayOf(PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))))
391391
) {
392392
val result = KotlinCompilation().apply {
393393
sources = listOf(SourceFile.kotlin("main.kt", source))
@@ -400,7 +400,7 @@ fun assertMessage(
400400
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
401401

402402
val kClazz = result.classLoader.loadClass("MainKt")
403-
val main = kClazz.declaredMethods.single { it.name == "main" }
403+
val main = kClazz.declaredMethods.single { it.name == "main" && it.parameterCount == 0 }
404404
try {
405405
try {
406406
main.invoke(null)

sample/build.gradle.kts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
buildscript {
22
dependencies {
3-
classpath("gradle.plugin.com.bnorm.power:kotlin-power-assert-gradle:0.1.0")
3+
classpath("gradle.plugin.com.bnorm.power:kotlin-power-assert-gradle:0.2.0")
44
}
55
}
66

77
plugins {
8-
kotlin("jvm") version "1.3.60"
8+
kotlin("jvm") version "1.3.70"
99
}
1010
apply(plugin = "com.bnorm.power.kotlin-power-assert")
1111

@@ -16,7 +16,6 @@ repositories {
1616
dependencies {
1717
implementation(kotlin("stdlib-jdk8"))
1818
testImplementation(kotlin("test-junit"))
19-
testImplementation("org.assertj:assertj-core:3.15.0")
2019
}
2120

2221
tasks.compileTestKotlin {
@@ -25,5 +24,5 @@ tasks.compileTestKotlin {
2524
}
2625

2726
configure<com.bnorm.power.PowerAssertGradleExtension> {
28-
functions = listOf("kotlin.test.AssertionsKt.assertTrue", "kotlin.PreconditionsKt.require")
27+
functions = listOf("kotlin.test.assertTrue", "kotlin.require")
2928
}

sample/src/test/kotlin/com/bnorm/power/PowerAssertTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ data class Person(
2525
)
2626

2727
class PowerAssertTest {
28-
private val people = listOf(Person("Brian", "Norman"), Person("Melinda", "Norman"))
28+
private val people = listOf(Person("John", "Doe"), Person("Jane", "Doe"))
2929

3030
@Test
3131
fun assertTrue() {

0 commit comments

Comments
 (0)