When an extension function is defined outside of a...
# scripting
d
When an extension function is defined outside of any class, script evaluation is not resolving it e.g. class X() operator fun X.plus(x:X) = 1 I cannot get + or plus to be resolved from within a script, but when I put the method in the class like class X () { operator fun plus( x: X) = 1 } then X() + X() works although a fully qualified X().packagename.plus( X()) cannot resolve 'plus' Im guessing this has to do with how extension functions are named and imported -- but I havent found the 'trick' to import them. Any suggestions ?
i
I just checked - it works for me. I defined a
.kt
file with your first def of the
X
and
plus
(in a package
test1
) then placed a script along with something like:
Copy code
mport test1.X
import test1.plus
val x = X() + X()
and
+
is properly resolved. Is your scenario different? PS. I’m using the latest eap of 1.3.50.
d
Im using 1.3.41 , and JSR232 basic script support.
i