Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.12k stars 107 forks source link

method 'void <init>()' not found #355

Open holgerbrandl opened 2 years ago

holgerbrandl commented 2 years ago

Consider the following example: https://github.com/holgerbrandl/kalasim/blob/master/docs/misc/callcenter_bugreport.ipynb

which fails with

Line_6$ShiftManager: method 'void <init>()' not found
java.lang.NoSuchMethodError: Line_6$ShiftManager: method 'void <init>()' not found
    at Line_7$SimpleCenter.<init>(Line_7.jupyter-kts:2)
    at Line_7.<init>(Line_7.jupyter-kts:5)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:100)
    at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke$suspendImpl(BasicJvmScriptEvaluator.kt:47)
    at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke(BasicJvmScriptEvaluator.kt)
    at kotlin.script.experimental.jvm.BasicJvmReplEvaluator.eval(BasicJvmReplEvaluator.kt:49)
    at org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl$eval$resultWithDiagnostics$1.invokeSuspend(InternalEvaluatorImpl.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)

The error seems to relate to the variable val shiftIt. When this variable is disabled, it runs without an error. So this may relate to #345 but I'm not sure.

ileasile commented 2 years ago

Yes, because of usage of "top-level" variable shiftModel inside ShiftManager it was implicitly made inner. It's the consequence of the recent fix for https://youtrack.jetbrains.com/issue/KT-19423. But the fix isn't complete: following cells don't know that the class is inner, and try to instantiate it as simple class by invoking <init>() method. Inner classes don't have <init>() constructor, they have <init>(o: Outer) instead. That's why you get what you get.

I need to make a proper fix for REPL too, so this bug will be fixed

holgerbrandl commented 1 year ago

Any news on this one?

AmanjeetCogoport commented 1 year ago

i am getting exactly the same error. how can i fix it?

holgerbrandl commented 11 months ago

Any chance that this could be fixed?