starke
06/23/2022, 10:25 PMfoo.main.kts
when I use @file:Import
, but can’t figure out a way to access classes that are defined in foo.main.kts
@file:Import("foo.main.kts")
I tried referencing the class like Foo_main.MyClass()
, but it doesn’t seem to work 🤔
Thanks in advance!ilya.chernikov
06/24/2022, 3:43 PMval foo = 1
class Bar {
val baz = foo + 1 // captures foo from the script
}
val x = Bar().baz // should work fine in the same script
fun makeBar() = Bar() // "constructor"
script2.main.kts
@file:Import("script1.main.kts")
println(makeBar().baz) // works
println(Bar().baz) // fails
(I realized that the issue is not documented yet, so I created the YT ticket to follow - https://youtrack.jetbrains.com/issue/KT-52957/Scripting-capturing-classes-constructors-are-not-called-correctly-from-an-importing-script-and-probably-in-REPL-too)starke
06/24/2022, 3:44 PMstarke
06/24/2022, 3:57 PMilya.chernikov
06/24/2022, 4:02 PMstarke
06/24/2022, 4:24 PM@file:DependsOn
to both scripts even if only the script that is imported by the other is directly using the dependency. Is that a known/expected issue?ilya.chernikov
06/24/2022, 5:08 PMstarke
06/27/2022, 5:09 PM