FIC: introduce language feature, modifiers checks and basic tests

This commit is contained in:
Mikhail Zarechenskiy
2019-11-12 03:19:45 +03:00
parent 303811cbd9
commit 55935cc98a
13 changed files with 24195 additions and 4 deletions
File diff suppressed because it is too large Load Diff
@@ -107,7 +107,8 @@ object ModifierCheckerCore {
ENUM_CLASS,
ANNOTATION_CLASS,
TYPEALIAS
)
),
FUN_KEYWORD to EnumSet.of(INTERFACE)
)
private val featureDependencies = mapOf(
@@ -117,14 +118,16 @@ object ModifierCheckerCore {
IMPL_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
EXPECT_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
ACTUAL_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
LATEINIT_KEYWORD to listOf(LanguageFeature.LateinitTopLevelProperties, LanguageFeature.LateinitLocalVariables)
LATEINIT_KEYWORD to listOf(LanguageFeature.LateinitTopLevelProperties, LanguageFeature.LateinitLocalVariables),
FUN_KEYWORD to listOf(LanguageFeature.FunctionInterfaceConversion)
)
private val featureDependenciesTargets = mapOf(
LanguageFeature.InlineProperties to setOf(PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER),
LanguageFeature.LateinitLocalVariables to setOf(LOCAL_VARIABLE),
LanguageFeature.LateinitTopLevelProperties to setOf(TOP_LEVEL_PROPERTY),
LanguageFeature.InlineClasses to setOf(CLASS_ONLY)
LanguageFeature.InlineClasses to setOf(CLASS_ONLY),
LanguageFeature.FunctionInterfaceConversion to setOf(INTERFACE)
)
// NOTE: deprecated targets must be possible!
@@ -412,7 +415,7 @@ object ModifierCheckerCore {
return false
}
private val MODIFIER_KEYWORD_SET = TokenSet.orSet(KtTokens.SOFT_KEYWORDS, TokenSet.create(KtTokens.IN_KEYWORD))
private val MODIFIER_KEYWORD_SET = TokenSet.orSet(SOFT_KEYWORDS, TokenSet.create(IN_KEYWORD, FUN_KEYWORD))
private fun checkModifierList(
list: KtModifierList,
@@ -0,0 +1,15 @@
// !LANGUAGE: +FunctionInterfaceConversion
fun interface Foo {
fun invoke(): String
}
class A : Foo {
override fun invoke(): String {
return "OK"
}
}
fun box(): String {
return A().invoke()
}
@@ -0,0 +1,5 @@
// !LANGUAGE: +FunctionInterfaceConversion
fun interface Foo {
fun invoke()
}
@@ -0,0 +1,8 @@
package
public interface Foo {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun invoke(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,5 @@
// !LANGUAGE: -FunctionInterfaceConversion
<!UNSUPPORTED_FEATURE!>fun<!> interface Foo {
fun invoke()
}
@@ -0,0 +1,8 @@
package
public interface Foo {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun invoke(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -7879,6 +7879,29 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
}
}
@TestMetadata("compiler/testData/diagnostics/tests/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractDiagnosticsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/funInterface"), Pattern.compile("^(.*)\\.kts?$"), true);
}
@TestMetadata("basicFunInterface.kt")
public void testBasicFunInterface() throws Exception {
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterface.kt");
}
@TestMetadata("basicFunInterfaceDisabled.kt")
public void testBasicFunInterfaceDisabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterfaceDisabled.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/functionAsExpression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -7874,6 +7874,29 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
}
}
@TestMetadata("compiler/testData/diagnostics/tests/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractDiagnosticsUsingJavacTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/funInterface"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("basicFunInterface.kt")
public void testBasicFunInterface() throws Exception {
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterface.kt");
}
@TestMetadata("basicFunInterfaceDisabled.kt")
public void testBasicFunInterfaceDisabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterfaceDisabled.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/functionAsExpression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -13668,6 +13668,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("basicFunInterface.kt")
public void testBasicFunInterface() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/basicFunInterface.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -13668,6 +13668,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractLightAnalysisModeTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("basicFunInterface.kt")
public void testBasicFunInterface() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/basicFunInterface.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -12518,6 +12518,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractIrBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
}
@TestMetadata("basicFunInterface.kt")
public void testBasicFunInterface() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/basicFunInterface.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -125,6 +125,7 @@ enum class LanguageFeature(
ProperVisibilityForCompanionObjectInstanceField(KOTLIN_1_4, kind = BUG_FIX),
DoNotGenerateThrowsForDelegatedKotlinMembers(KOTLIN_1_4),
ProperIeee754Comparisons(KOTLIN_1_4, kind = BUG_FIX),
FunctionInterfaceConversion(KOTLIN_1_4, kind = UNSTABLE_FEATURE),
// Temporarily disabled, see KT-27084/KT-22379
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),