From 5cfc15cf17f27d79ef5f1ac3c6fb82c97fccc77b Mon Sep 17 00:00:00 2001 From: sergeych Date: Thu, 4 Dec 2025 16:09:27 +0100 Subject: [PATCH] fix #72 comments are allowed in class constructor; some configuration bigs fixed --- gradle.properties | 4 +-- lynglib/build.gradle.kts | 24 +++++++++++++ .../kotlin/net/sergeych/lyng/Compiler.kt | 1 + lynglib/src/commonTest/kotlin/ScriptTest.kt | 35 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index cb129d9..ef520ed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,9 +32,9 @@ kotlin.native.cacheKind.linuxX64=none # Workaround: Ensure Gradle uses a JDK with `jlink` available for AGP's JDK image transform. # On this environment, the system JDK 21 installation lacks `jlink`, causing -# :lynglib:androidJdkImage to fail. Point Gradle to JDK 17 which includes `jlink`. +# :lynglib:androidJdkImage to fail. Point Gradle to a JDK that includes `jlink`. # This affects only the JDK Gradle runs with; Kotlin/JVM target remains compatible. -#org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64 +org.gradle.java.home=/home/sergeych/.jdks/corretto-21.0.9 android.experimental.lint.migrateToK2=false android.lint.useK2Uast=false kotlin.mpp.applyDefaultHierarchyTemplate=true \ No newline at end of file diff --git a/lynglib/build.gradle.kts b/lynglib/build.gradle.kts index e9013d9..7531e62 100644 --- a/lynglib/build.gradle.kts +++ b/lynglib/build.gradle.kts @@ -176,6 +176,30 @@ kotlin.targets.configureEach { } } +// Ensure any SourcesJar tasks (for all targets/variants) are properly wired to the generator +tasks.withType().configureEach { + if (name == "sourcesJar" || name.endsWith("SourcesJar")) { + // Declare both dependency and inputs to satisfy Gradle validation and up-to-date checks + dependsOn(generateLyngStdlib) + inputs.dir(generatedLyngStdlibDir) + } +} + +// Extra safety: in case the SourcesJar task is not of type Jar (AGP/MPP variations), +// wire it up by name as well. This guarantees the dependency even if the concrete type differs. +tasks.configureEach { + if (name == "androidReleaseSourcesJar" || name == "sourcesJar" || name.endsWith("SourcesJar")) { + dependsOn(generateLyngStdlib) + inputs.dir(generatedLyngStdlibDir) + } +} + +// Be explicit for the aggregate metadata sources task too +tasks.named("sourcesJar").configure { + dependsOn(generateLyngStdlib) + inputs.dir(generatedLyngStdlibDir) +} + android { namespace = "org.jetbrains.kotlinx.multiplatform.library.template" compileSdk = libs.versions.android.compileSdk.get().toInt() diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index 5822864..b3affbc 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -832,6 +832,7 @@ class Compiler( } Token.Type.NEWLINE -> {} + Token.Type.MULTILINE_COMMENT, Token.Type.SINLGE_LINE_COMMENT -> {} Token.Type.ID -> { // visibility diff --git a/lynglib/src/commonTest/kotlin/ScriptTest.kt b/lynglib/src/commonTest/kotlin/ScriptTest.kt index d3cf53c..e732bf7 100644 --- a/lynglib/src/commonTest/kotlin/ScriptTest.kt +++ b/lynglib/src/commonTest/kotlin/ScriptTest.kt @@ -15,6 +15,7 @@ * */ + import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.map @@ -30,6 +31,22 @@ import net.sergeych.tools.bm import kotlin.test.* import kotlin.time.Duration.Companion.seconds +/* + * Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ class ScriptTest { @Test fun testVersion() { @@ -3766,4 +3783,22 @@ class ScriptTest { """.trimIndent()) } + @Test + fun testCommentsInClassConstructor() = runTest { + eval(""" + class T( + // comment 1 + val x: Int, + // comment 2 + val y: String + ) + + println( T(1, "2") ) + + """ + ) + + + } + }