From bf08359f0dbd14984bd95c777744b7d88637a564 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 6 Oct 2017 11:34:25 +0300 Subject: [PATCH] unit-tests: Report error on test functions with incorrect signature --- .../kotlin/backend/konan/lower/TestProcessor.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index f44d1b2d3c3..0c02d3512bb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -230,6 +230,20 @@ internal class TestProcessor (val context: KonanBackendContext) { } } + fun IrFunction.checkFunctionSignature() { + // Test runner requires test functions to have the following signature: () -> Unit. + if (descriptor.returnType != context.builtIns.unitType) { + context.reportCompilationError( + "Test function must return Unit: ${descriptor.fqNameSafe}", irFile, this + ) + } + if (descriptor.valueParameters.isNotEmpty()) { + context.reportCompilationError( + "Test function must have no arguments: ${descriptor.fqNameSafe}", irFile, this + ) + } + } + // TODO: Use symbols instead of containingDeclaration when such information is available. override fun visitFunction(declaration: IrFunction) { val symbol = declaration.symbol @@ -239,6 +253,7 @@ internal class TestProcessor (val context: KonanBackendContext) { if (kinds.isEmpty()) { return } + declaration.checkFunctionSignature() when (owner) { is PackageFragmentDescriptor -> topLevelFunctions.registerFunction(symbol, kinds)