add test for check access to internal elements from another module
#KT-9178 Fixed
Original commit: 4d9eaf19c3
This commit is contained in:
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil
|
|||||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import org.jetbrains.org.objectweb.asm.ClassReader
|
import org.jetbrains.org.objectweb.asm.ClassReader
|
||||||
@@ -472,6 +473,23 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
checkWhen(touch("module2/src/b.kt"), null, packageClasses("module2", "module2/src/b.kt", "test.TestPackage"))
|
checkWhen(touch("module2/src/b.kt"), null, packageClasses("module2", "module2/src/b.kt", "test.TestPackage"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun testInternalFromAnotherModule() {
|
||||||
|
initProject()
|
||||||
|
val result = makeAll()
|
||||||
|
result.assertFailed()
|
||||||
|
|
||||||
|
val module2File = File(workDir, "module2/src/module2.kt")
|
||||||
|
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(FileUtilRt.loadFile(module2File), "// ERROR:")
|
||||||
|
.sorted()
|
||||||
|
.joinToString("\n")
|
||||||
|
val actualErrors = result.getMessages(BuildMessage.Kind.ERROR)
|
||||||
|
.map { it.messageText }
|
||||||
|
.map { it.replace("^.+:\\d+:\\s+".toRegex(), "").trim() }
|
||||||
|
.sorted()
|
||||||
|
.joinToString("\n")
|
||||||
|
assertEquals(expectedErrors, actualErrors, "Error messages were different")
|
||||||
|
}
|
||||||
|
|
||||||
public fun testCircularDependencyWithReferenceToOldVersionLib() {
|
public fun testCircularDependencyWithReferenceToOldVersionLib() {
|
||||||
initProject()
|
initProject()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
|
<resourceExtensions />
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
<component name="CopyrightManager" default="">
|
||||||
|
<module2copyright />
|
||||||
|
</component>
|
||||||
|
<component name="DependencyValidationManager">
|
||||||
|
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||||
|
</component>
|
||||||
|
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/module1/module1.iml" filepath="$PROJECT_DIR$/module1/module1.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/module2/module2.iml" filepath="$PROJECT_DIR$/module2/module2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal open class InternalClass1
|
||||||
|
|
||||||
|
abstract class ClassA1(internal val member: Int)
|
||||||
|
|
||||||
|
abstract class ClassB1 {
|
||||||
|
internal abstract val member: Int
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module" module-name="module1" />
|
||||||
|
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal open class InternalClass2
|
||||||
|
|
||||||
|
abstract class ClassA2(internal val member: Int)
|
||||||
|
|
||||||
|
abstract class ClassB2 {
|
||||||
|
internal abstract val member: Int
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// ERROR: 'internal open val member: kotlin.Int defined in test.ClassBB1' has no access to 'internal abstract val member: kotlin.Int defined in test.ClassB1', so it cannot override it
|
||||||
|
// ERROR: Cannot access 'InternalClass1': it is 'internal' in 'test'
|
||||||
|
// ERROR: Cannot access 'member': it is 'invisible_fake' in 'ClassAA1'
|
||||||
|
package test
|
||||||
|
|
||||||
|
// InternalClass1, ClassA1, ClassB1 are in module1
|
||||||
|
class ClassInheritedFromInternal1: InternalClass1()
|
||||||
|
|
||||||
|
class ClassAA1 : ClassA1(10)
|
||||||
|
|
||||||
|
class ClassBB1 : ClassB1() {
|
||||||
|
internal override val member = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
// InternalClass2, ClassA2, ClassB2 are in module2
|
||||||
|
class ClassInheritedFromInternal2: InternalClass2()
|
||||||
|
|
||||||
|
class ClassAA2 : ClassA2(10)
|
||||||
|
|
||||||
|
class ClassBB2 : ClassB2() {
|
||||||
|
internal override val member = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
fun f() {
|
||||||
|
val x1 = ClassAA1().member
|
||||||
|
val x2 = ClassAA2().member
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user