From 25abc16e453cd4a4a8a7593bbd2846f9be06118d Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Sun, 10 Sep 2023 13:21:17 +0200 Subject: [PATCH] A top-level function declaration may not have a body --- .../kotlin/internal/KotlinParserVisitor.kt | 4 +++- .../kotlin/tree/MethodDeclarationTest.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/openrewrite/kotlin/internal/KotlinParserVisitor.kt b/src/main/kotlin/org/openrewrite/kotlin/internal/KotlinParserVisitor.kt index 3ee2bab67..f389428cf 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/internal/KotlinParserVisitor.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/internal/KotlinParserVisitor.kt @@ -2671,7 +2671,7 @@ class KotlinParserVisitor( returnTypeExpression = visitElement(simpleFunction.returnTypeRef, data) as TypeTree? saveCursor = cursor before = whitespace() - if (source[cursor] == '?') { + if (at('?')) { returnTypeExpression = returnTypeExpression!!.withMarkers( returnTypeExpression.markers.addIfAbsent(IsNullable(randomId(), before)) ) @@ -4878,6 +4878,8 @@ class KotlinParserVisitor( return if (currentFile == null) null else currentFile!!.symbol } + private fun at(c: Char) = cursor < source.length && source[cursor] == c + private fun skip(token: String?): Boolean { if (token != null && source.startsWith(token, cursor)) { cursor += token.length diff --git a/src/test/java/org/openrewrite/kotlin/tree/MethodDeclarationTest.java b/src/test/java/org/openrewrite/kotlin/tree/MethodDeclarationTest.java index 77d1b2aed..b1d0216a2 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/MethodDeclarationTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/MethodDeclarationTest.java @@ -322,4 +322,15 @@ fun size(): Int = (-1) ) ); } + + @Test + void multiplatformExpectDeclaration() { + rewriteRun( + kotlin( + """ + expect suspend fun Any.executeAsync(): Any + """ + ) + ); + } }