Check "kotlin" package usage when compiling common code

#KT-25369 Fixed
This commit is contained in:
Alexander Udalov
2018-07-24 13:43:32 +02:00
parent ddd3a0a46e
commit 3323fd5a11
5 changed files with 19 additions and 5 deletions
@@ -17,10 +17,7 @@
package org.jetbrains.kotlin.cli.metadata
import com.intellij.openapi.Disposable
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.cli.common.messages.MessageUtil
@@ -71,6 +68,8 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
configuration.put(CommonConfigurationKeys.MODULE_NAME, arguments.moduleName ?: JvmAbi.DEFAULT_MODULE_NAME)
configuration.put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
val destination = arguments.destination
if (destination != null) {
if (destination.endsWith(".jar")) {
@@ -90,6 +89,8 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
return ExitCode.COMPILATION_ERROR
}
checkKotlinPackageUsage(environment, environment.getSourceFiles())
try {
val metadataVersion =
configuration.get(CommonConfigurationKeys.METADATA_VERSION) as? BuiltInsBinaryVersion ?: BuiltInsBinaryVersion.INSTANCE
+3
View File
@@ -0,0 +1,3 @@
$TESTDATA_DIR$/../kotlinPackage.kt
-d
$TEMP_DIR$
+4
View File
@@ -0,0 +1,4 @@
compiler/testData/cli/kotlinPackage.kt:1:1: error: only the Kotlin standard library is allowed to use the 'kotlin' package
package kotlin.mylibrary
^
COMPILATION_ERROR
@@ -865,6 +865,11 @@ public class CliTestGenerated extends AbstractCliTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cli/metadata"), Pattern.compile("^(.+)\\.args$"), TargetBackend.ANY, false);
}
@TestMetadata("kotlinPackage.args")
public void testKotlinPackage() throws Exception {
runTest("compiler/testData/cli/metadata/kotlinPackage.args");
}
@TestMetadata("moduleName.args")
public void testModuleName() throws Exception {
runTest("compiler/testData/cli/metadata/moduleName.args");
+2 -1
View File
@@ -81,7 +81,8 @@ compileCoroutinesKotlinCommon {
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs = [
"-module-name", project.name
"-module-name", project.name,
"-Xallow-kotlin-package"
]
}
}