Report error on calls to obsolete inline suspend functions

They do not contain markers for suspend calls in them

See the changes introduced for fixing KT-16603
This commit is contained in:
Denis Zharkov
2017-06-15 14:56:17 +03:00
parent 6441c9d913
commit cb95986c36
12 changed files with 115 additions and 29 deletions
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2017 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.load.kotlin
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
fun CallableDescriptor.getContainingKotlinJvmBinaryClass(): KotlinJvmBinaryClass? {
if (this !is DeserializedCallableMemberDescriptor) return null
val container = containingDeclaration
return when (container) {
is DeserializedClassDescriptor ->
container.source.safeAs<KotlinJvmBinarySourceElement>()?.binaryClass
is LazyJavaPackageFragment ->
container.source.safeAs<KotlinJvmBinaryPackageSourceElement>()?.getRepresentativeBinaryClass()
else -> null
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2017 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.jvm.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.load.kotlin.getContainingKotlinJvmBinaryClass
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
object ObsoleteABIForInlineSuspendFunctionCallChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val candidateDescriptor = resolvedCall.candidateDescriptor as? FunctionDescriptor ?: return
if (!candidateDescriptor.isSuspend || !candidateDescriptor.isInline) return
val jvmBytecodeVersion = candidateDescriptor.getContainingKotlinJvmBinaryClass()?.classHeader?.bytecodeVersion ?: return
if (!jvmBytecodeVersion.isAtLeast(1, 0, 2)) {
context.trace.report(ErrorsJvm.OBSOLETE_SUSPEND_INLINE_FUNCTIONS_ABI.on(reportOn))
}
}
}
@@ -112,6 +112,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET, "Calls to static methods in Java interfaces are deprecated in JVM target 1.6. Recompile with '-jvm-target 1.8'");
MAP.put(INLINE_FROM_HIGHER_PLATFORM, "Cannot inline bytecode built with {0} into bytecode that is being built with {1}. Please specify proper ''-jvm-target'' option", STRING, STRING);
MAP.put(ErrorsJvm.OBSOLETE_SUSPEND_INLINE_FUNCTIONS_ABI, "Cannot inline suspend function built with compiler version less than 1.1.4/1.2-M1");
}
@NotNull
@@ -93,6 +93,7 @@ public interface ErrorsJvm {
DiagnosticFactory0<PsiElement> INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET = DiagnosticFactory0.create(WARNING);
DiagnosticFactory2<PsiElement, String, String> INLINE_FROM_HIGHER_PLATFORM = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<PsiElement> OBSOLETE_SUSPEND_INLINE_FUNCTIONS_ABI = DiagnosticFactory0.create(ERROR);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -52,7 +52,8 @@ object JvmPlatformConfigurator : PlatformConfigurator(
UnsupportedSyntheticCallableReferenceChecker(),
SuperCallWithDefaultArgumentsChecker(),
ProtectedSyntheticExtensionCallChecker,
ReifiedTypeParameterSubstitutionChecker()
ReifiedTypeParameterSubstitutionChecker(),
ObsoleteABIForInlineSuspendFunctionCallChecker
),
additionalTypeCheckers = listOf(