Can't access internal functions from test module


#1

Hi there,

Say that I have 2 files:

  • src/main/kotlin/sample/Hello.kt
package sample

internal fun callMe() = "hello"
  • src/test/kotlin/sample/HelloTest.kt
package sample

fun testCallMe() = callMe()

When I try to compile this I get the following error (gradle and idea):

e: C:\Development\Projects\kotlin-js-example\src\test\kotlin\sample\HelloTest.kt: (10, 20): Cannot access 'callMe': it is internal in 'sample'

I expected this to work, because both functions are defined in the same package. The reference resolves in the IDEA editor. Is it possible to make this call compile?

Here’s my gradle config:

apply plugin: 'kotlin2js'

sourceSets {
    main.kotlin.srcDirs += "src/main/kotlin"
    test.kotlin.srcDirs += "src/test/kotlin"
}

compileKotlin2Js {
    kotlinOptions.moduleKind = "amd"
    kotlinOptions.sourceMap = true
}

compileTestKotlin2Js {
    kotlinOptions.moduleKind = "amd"
    kotlinOptions.sourceMap = true
}

#2

Which Kotlin version are you using? As far as I know, this problem is fixed in Kotlin 1.1-RC.


#3

I’m using 1.1.0-rc-91.
I created a branch for you to easily reproduce the error:

git clone https://github.com/bascan/kotlin-js-example.git
git checkout internal-call-error
cd kotlin-js-example
./gradlew clean build

Cheers,
Bas


#4

Could you please file a YouTrack issue describing this problem? Thanks!


#5

Done: https://youtrack.jetbrains.com/issue/KT-16497