Skip to content

Commit 514c956

Browse files
committed
fixed #181: Confusing error when filename starts with a number
1 parent 6c68da8 commit 514c956

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/main/kotlin/kscript/app/Kscript.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ fun main(args: Array<String>) {
185185
val className = scriptFile.nameWithoutExtension
186186
.replace("[^A-Za-z0-9]".toRegex(), "_")
187187
.capitalize()
188+
// also make sure that it is a valid identifier by avoiding an initial digit (to stay in sync with what the kotlin script compiler will do as well)
189+
.let { if ("^[0-9]".toRegex().containsMatchIn(it)) "_" + it else it }
188190

189191

190192
// Define the entrypoint for the scriptlet jar

0 commit comments

Comments
 (0)