Kotlin / kotlin-interactive-shell

Kotlin Language Interactive Shell
Apache License 2.0
587 stars 36 forks source link

Ki-shell and if #113

Closed LaurentBerger closed 2 years ago

LaurentBerger commented 2 years ago

Hi,

OS windows10 x64 I trie this script :

var a = 18
var b = 19
var c = if (a>17) b else a
println(c)

and I runned it using kotlinc -script if_test1.kts result is 19

I tried this and just after typing b (vithout enter) I have got this error :

ki-shell 0.4.5/1.6.10
type :h for help
[0] var a = 18
[1] var b = 19
[2] var c = if (a>17) b

java.lang.NullPointerException
        at org.jetbrains.kotlinx.ki.shell.parser.KotlinParserListenerForHighlighting.exitIfExpression(KotlinParserListenerForHighlighting.kt:679)
        at org.jetbrains.kotlinx.ki.shell.parser.KotlinParser$IfExpressionContext.exitRule(KotlinParser.java:13491)
        at org.antlr.v4.runtime.Parser.triggerExitRuleEvent(Parser.java:408)
        at org.antlr.v4.runtime.Parser.exitRule(Parser.java:642)
        at org.jetbrains.kotlinx.ki.shell.parser.KotlinParser.script(KotlinParser.java:514)
        at org.jetbrains.kotlinx.ki.shell.plugins.KotlinHighlighter.buildHighlighting(KotlinHighlighter.kt:39)
        at org.jetbrains.kotlinx.ki.shell.plugins.KotlinHighlighter.highlight(KotlinHighlighter.kt:20)
        at org.jetbrains.kotlinx.ki.shell.plugins.BaseHighlighter$DefaultImpls.highlight$default(BaseHighlighter.kt:8)
        at org.jetbrains.kotlinx.ki.shell.plugins.BaseHighlighter$DefaultImpls.highlight(BaseHighlighter.kt:11)
        at org.jetbrains.kotlinx.ki.shell.plugins.KotlinHighlighter.highlight(KotlinHighlighter.kt:13)
        at org.jetbrains.kotlinx.ki.shell.ContextHighlighter.highlight(ContextHighlighter.kt:16)
        at org.jline.reader.impl.LineReaderImpl.getHighlightedBuffer(LineReaderImpl.java:4041)
        at org.jline.reader.impl.LineReaderImpl.getDisplayedBufferWithPrompts(LineReaderImpl.java:3980)
        at org.jline.reader.impl.LineReaderImpl.redisplay(LineReaderImpl.java:3848)
        at org.jline.reader.impl.LineReaderImpl.redisplay(LineReaderImpl.java:3784)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:708)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:468)
        at org.jetbrains.kotlinx.ki.shell.Shell.doRun(Shell.kt:205)
        at org.jetbrains.kotlinx.ki.shell.KotlinShell.main(KotlinShell.kt:52)
[2]

What’s wrong here?

asm0dey commented 2 years ago

Hi, @LaurentBerger

It looks like you've copied the third expression to ki incorrectly. var c = if (a>17) b else a works like a charm for me, while var c = if (a>17) b is indeed semantically incorrect

LaurentBerger commented 2 years ago

@asm0dey When I type var c = if (a>17) b error occurs without a return I cannot enter else using keyboard error occurs..

asm0dey commented 2 years ago

@LaurentBerger oh, now I get you. Could you please try the latest 0.5.1 version? Before I will start checking on the different OS :)

LaurentBerger commented 2 years ago

@asm0dey Oops

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/kotlinx/ki/shell/KotlinShell has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I must update something

LaurentBerger commented 2 years ago

solved I have installed jdk 18

but an other error now:

ki-shell 0.5.0/1.7.0
type :h for help
[0] var a = 17
java.lang.IllegalStateException: Unknown outcome
        at org.jetbrains.kotlinx.ki.shell.Shell.handleSuccess(Shell.kt:310)
        at org.jetbrains.kotlinx.ki.shell.Shell.doRun$evalSnippet(Shell.kt:197)
        at org.jetbrains.kotlinx.ki.shell.Shell.doRun(Shell.kt:230)
        at org.jetbrains.kotlinx.ki.shell.KotlinShell.main(KotlinShell.kt:52)

problem is at beginning :pressed enter after [0] there is a problem

ki-shell 0.5.0/1.7.0
type :h for help
[0]
java.lang.IllegalStateException: Unknown outcome
        at org.jetbrains.kotlinx.ki.shell.Shell.handleSuccess(Shell.kt:310)
        at org.jetbrains.kotlinx.ki.shell.Shell.doRun$evalSnippet(Shell.kt:197)
        at org.jetbrains.kotlinx.ki.shell.Shell.doRun(Shell.kt:230)
        at org.jetbrains.kotlinx.ki.shell.KotlinShell.main(KotlinShell.kt:52)
asm0dey commented 2 years ago

It's a known issue on 0.5.0, please try 0.5.1

ср, 29 июн. 2022 г., 19:58 Laurent Berger @.***>:

solved I have installed jdk 18 https://www.oracle.com/java/technologies/downloads/#jdk18-windows

but an other error now:

ki-shell 0.5.0/1.7.0 type :h for help [0] var a = 17 java.lang.IllegalStateException: Unknown outcome at org.jetbrains.kotlinx.ki.shell.Shell.handleSuccess(Shell.kt:310) at org.jetbrains.kotlinx.ki.shell.Shell.doRun$evalSnippet(Shell.kt:197) at org.jetbrains.kotlinx.ki.shell.Shell.doRun(Shell.kt:230) at org.jetbrains.kotlinx.ki.shell.KotlinShell.main(KotlinShell.kt:52)

— Reply to this email directly, view it on GitHub https://github.com/Kotlin/kotlin-interactive-shell/issues/113#issuecomment-1170240393, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ4XATJZJT4ACMWZG6RMD3VRR6D5ANCNFSM52CD7TRQ . You are receiving this because you were mentioned.Message ID: @.***>

LaurentBerger commented 2 years ago

Solved 0.5.1 and jdk 18

ki-shell 0.5.1/1.7.0
type :h for help
[0] var a = 18
[1] var b = 19
[2] var c = if (a>17) b else 20
[3] println(c)
19
asm0dey commented 2 years ago

@LaurentBerger does it work with jdk11 for you?

asm0dey commented 2 years ago

The input of 0.5.1 looks correct to me. Is it?

LaurentBerger commented 2 years ago

Yes everything is correct About jdk 11 it's not available without an oracle account (https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html)

asm0dey commented 2 years ago

Well, for example Azul's builds are available: https://www.azul.com/downloads/?package=jdk#download-openjdk

I think the the issue is resolved, do not hesitate to report if it should be reopened

asm0dey commented 1 year ago

Yes, it required Java 11. Do you have an option to use it?

вт, 28 июн. 2022 г., 22:46 Laurent Berger @.***>:

@asm0dey https://github.com/asm0dey Oops

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/kotlinx/ki/shell/KotlinShell has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I must update something

— Reply to this email directly, view it on GitHub https://github.com/Kotlin/kotlin-interactive-shell/issues/113#issuecomment-1169160854, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ4XAXK55SUXJYMBR7H65LVRNJC3ANCNFSM52CD7TRQ . You are receiving this because you were mentioned.Message ID: @.***>