Do not deserialize type aliases in compatibility mode
When "-language-version 1.0" is specified in command line arguments, the compiler should not be able to see the declarations of type aliases in libraries, because that corresponds to the behavior of the compiler of version 1.0. Note that type aliases are _completely invisible_ in this mode (i.e. "unresolved reference" is reported) because they must not interfere with the classifier resolution
This commit is contained in:
+5
-1
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
|
||||
class CompilerDeserializationConfiguration(private val languageVersionSettings: LanguageVersionSettings) : DeserializationConfiguration
|
||||
class CompilerDeserializationConfiguration(private val languageVersionSettings: LanguageVersionSettings) : DeserializationConfiguration {
|
||||
override val typeAliasesAllowed: Boolean
|
||||
get() = languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import test.*
|
||||
import test.Str
|
||||
|
||||
fun use(
|
||||
str: Str,
|
||||
l: L<Str>,
|
||||
nested: Klass.Nested
|
||||
) {}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:2:13: error: unresolved reference: Str
|
||||
import test.Str
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:5:14: error: unresolved reference: Str
|
||||
str: Str,
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:6:12: error: unresolved reference: L
|
||||
l: L<Str>,
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:6:14: error: unresolved reference: Str
|
||||
l: L<Str>,
|
||||
^
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:7:23: error: unresolved reference: Nested
|
||||
nested: Klass.Nested
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package test
|
||||
|
||||
typealias Str = String
|
||||
typealias L<T> = List<T>
|
||||
|
||||
class Klass {
|
||||
typealias Nested = Z
|
||||
|
||||
class Z
|
||||
}
|
||||
+13
-8
@@ -188,14 +188,14 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
@NotNull File output,
|
||||
@NotNull File... classpath
|
||||
) {
|
||||
return compileKotlin(fileName, output, false, classpath);
|
||||
return compileKotlin(fileName, output, Collections.<String>emptyList(), classpath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Pair<String, ExitCode> compileKotlin(
|
||||
@NotNull String fileName,
|
||||
@NotNull File output,
|
||||
boolean jvm8Target,
|
||||
List<String> additionalOptions,
|
||||
@NotNull File... classpath
|
||||
) {
|
||||
List<String> args = new ArrayList<String>();
|
||||
@@ -208,10 +208,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
}
|
||||
args.add("-d");
|
||||
args.add(output.getPath());
|
||||
if (jvm8Target) {
|
||||
args.add("-jvm-target");
|
||||
args.add("1.8");
|
||||
}
|
||||
args.addAll(additionalOptions);
|
||||
|
||||
return AbstractCliTest.executeCompilerGrabOutput(new K2JVMCompiler(), args);
|
||||
}
|
||||
@@ -427,9 +424,17 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
private void target6Inheritance() {
|
||||
compileKotlin("target6.kt", tmpdir);
|
||||
|
||||
compileKotlin("main.kt", tmpdir, true, tmpdir);
|
||||
Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, Arrays.asList("-jvm-target", "1.8"), tmpdir);
|
||||
|
||||
Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, true, tmpdir);
|
||||
KotlinTestUtils.assertEqualsToFile(
|
||||
new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputMain)
|
||||
);
|
||||
}
|
||||
|
||||
public void testTypeAliasesAreInvisibleInCompatibilityMode() {
|
||||
compileKotlin("typeAliases.kt", tmpdir);
|
||||
|
||||
Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, Arrays.asList("-language-version", "1.0"), tmpdir);
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(
|
||||
new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputMain)
|
||||
|
||||
+3
@@ -17,5 +17,8 @@
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
interface DeserializationConfiguration {
|
||||
val typeAliasesAllowed: Boolean
|
||||
get() = true
|
||||
|
||||
object Default : DeserializationConfiguration
|
||||
}
|
||||
|
||||
+3
-1
@@ -51,7 +51,9 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
private val typeAliasProtos by
|
||||
c.storageManager.createLazyValue {
|
||||
typeAliasList.groupByName { it.name }
|
||||
if (c.components.configuration.typeAliasesAllowed)
|
||||
typeAliasList.groupByName { it.name }
|
||||
else emptyMap()
|
||||
}
|
||||
|
||||
private val functions =
|
||||
|
||||
Reference in New Issue
Block a user