diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt index 9c285dca5ba..6b2727ff79f 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt @@ -223,40 +223,4 @@ class TypeParameterBoundIsNotArrayChecker : SimpleDeclarationChecker { } } } -} - -class ReifiedTypeParameterAnnotationChecker : SimpleDeclarationChecker { - - override fun check( - declaration: KtDeclaration, - descriptor: DeclarationDescriptor, - diagnosticHolder: DiagnosticSink, - bindingContext: BindingContext - ) { - if (descriptor is CallableDescriptor && - !(InlineUtil.isInline(descriptor) || InlineUtil.isPropertyWithAllAccessorsAreInline(descriptor))) { - checkTypeParameterDescriptorsAreNotReified(descriptor.typeParameters, diagnosticHolder) - } - - if (descriptor is ClassDescriptor) { - checkTypeParameterDescriptorsAreNotReified(descriptor.declaredTypeParameters, diagnosticHolder) - } - } - - - private fun checkTypeParameterDescriptorsAreNotReified( - typeParameterDescriptors: List, - diagnosticHolder: DiagnosticSink - ) { - for (reifiedTypeParameterDescriptor in typeParameterDescriptors.filter { it.isReified }) { - val typeParameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(reifiedTypeParameterDescriptor) - if (typeParameterDeclaration !is KtTypeParameter) throw AssertionError("JetTypeParameter expected") - - diagnosticHolder.report( - Errors.REIFIED_TYPE_PARAMETER_NO_INLINE.on( - typeParameterDeclaration.getModifierList()!!.getModifier(KtTokens.REIFIED_KEYWORD)!! - ) - ) - } - } -} +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index c4a7faa53c5..98b7e7f21d7 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -37,7 +37,6 @@ object JvmPlatformConfigurator : PlatformConfigurator( VolatileAnnotationChecker(), SynchronizedAnnotationChecker(), LocalFunInlineChecker(), - ReifiedTypeParameterAnnotationChecker(), ExternalFunChecker(), OverloadsAnnotationChecker(), JvmFieldApplicabilityChecker(), diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt index f8117b7853f..0bddedd6caf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt @@ -65,7 +65,8 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf( InfixModifierChecker(), SuspendModifierChecker, CoroutineModifierChecker, - SinceKotlinAnnotationValueChecker + SinceKotlinAnnotationValueChecker, + ReifiedTypeParameterAnnotationChecker() ) private val DEFAULT_CALL_CHECKERS = listOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ReifiedTypeParameterAnnotationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ReifiedTypeParameterAnnotationChecker.kt new file mode 100644 index 00000000000..20e810cc644 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ReifiedTypeParameterAnnotationChecker.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve.checkers + +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.diagnostics.DiagnosticSink +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtTypeParameter +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.inline.InlineUtil + +class ReifiedTypeParameterAnnotationChecker : SimpleDeclarationChecker { + + override fun check( + declaration: KtDeclaration, + descriptor: DeclarationDescriptor, + diagnosticHolder: DiagnosticSink, + bindingContext: BindingContext + ) { + if (descriptor is CallableDescriptor && + !(InlineUtil.isInline(descriptor) || InlineUtil.isPropertyWithAllAccessorsAreInline(descriptor))) { + checkTypeParameterDescriptorsAreNotReified(descriptor.typeParameters, diagnosticHolder) + } + + if (descriptor is ClassDescriptor) { + checkTypeParameterDescriptorsAreNotReified(descriptor.declaredTypeParameters, diagnosticHolder) + } + } + + + private fun checkTypeParameterDescriptorsAreNotReified( + typeParameterDescriptors: List, + diagnosticHolder: DiagnosticSink + ) { + for (reifiedTypeParameterDescriptor in typeParameterDescriptors.filter { it.isReified }) { + val typeParameterDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(reifiedTypeParameterDescriptor) + if (typeParameterDeclaration !is KtTypeParameter) throw AssertionError("JetTypeParameter expected") + + diagnosticHolder.report( + Errors.REIFIED_TYPE_PARAMETER_NO_INLINE.on( + typeParameterDeclaration.getModifierList()!!.getModifier(KtTokens.REIFIED_KEYWORD)!! + ) + ) + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt index 2699a109364..d72e046ca0a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -REIFIED_TYPE_PARAMETER_NO_INLINE fun foo(t: T) {} class C(t: T) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt new file mode 100644 index 00000000000..b8897e923ff --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt @@ -0,0 +1,6 @@ +class C<reified T> + +val <reified T> T.v: T + get() = throw UnsupportedOperationException() + +fun <reified T> bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.txt b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.txt new file mode 100644 index 00000000000..bc67d1b9849 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.txt @@ -0,0 +1,11 @@ +package + +public val T.v: T +public fun bar(): kotlin.Unit + +public final class C { + public constructor C() + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index e786c390a7f..8d8ed5a58f6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -249,6 +249,21 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes } } + @TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/inline") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Inline extends AbstractDiagnosticsTestWithJsStdLib { + public void testAllFilesPresentInInline() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/inline"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("Reified.kt") + public void testReified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)