Add diagnostics tests. Forbid callable reference to coroutineContext
#KT-16908: Fixed
This commit is contained in:
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.platform
|
||||
@@ -89,18 +78,15 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap {
|
||||
}
|
||||
|
||||
// TODO: support also functions with >= 23 parameters
|
||||
val kFunction = FunctionClassDescriptor.Kind.KFunction
|
||||
val kFun = kFunction.packageFqName.toString() + "." + kFunction.classNamePrefix
|
||||
for (i in 0..22) {
|
||||
add(ClassId.topLevel(FqName("kotlin.jvm.functions.Function" + i)), KotlinBuiltIns.getFunctionClassId(i))
|
||||
|
||||
val kFunction = FunctionClassDescriptor.Kind.KFunction
|
||||
val kFun = kFunction.packageFqName.toString() + "." + kFunction.classNamePrefix
|
||||
addKotlinToJava(FqName(kFun + i), ClassId.topLevel(FqName(kFun)))
|
||||
}
|
||||
for (i in 0 until 22) {
|
||||
val kSuspendFunction = FunctionClassDescriptor.Kind.KSuspendFunction
|
||||
val kFunction = FunctionClassDescriptor.Kind.KFunction
|
||||
val kSuspendFun = kSuspendFunction.packageFqName.toString() + "." + kSuspendFunction.classNamePrefix
|
||||
val kFun = kFunction.packageFqName.toString() + "." + kFunction.classNamePrefix
|
||||
addKotlinToJava(FqName(kSuspendFun + i), ClassId.topLevel(FqName(kFun)))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.builtins
|
||||
@@ -64,28 +53,17 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
KotlinTypeFactory.simpleNotNullType(annotations, kClass, listOf(TypeProjectionImpl(variance, type)))
|
||||
|
||||
fun getKFunctionType(
|
||||
annotations: Annotations,
|
||||
receiverType: KotlinType?,
|
||||
parameterTypes: List<KotlinType>,
|
||||
parameterNames: List<Name>?,
|
||||
returnType: KotlinType,
|
||||
builtIns: KotlinBuiltIns
|
||||
): SimpleType {
|
||||
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, parameterNames, returnType, builtIns)
|
||||
val classDescriptor = getKFunction(arguments.size - 1 /* return type */)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
||||
}
|
||||
|
||||
fun getKSuspendFunctionType(
|
||||
annotations: Annotations,
|
||||
receiverType: KotlinType?,
|
||||
parameterTypes: List<KotlinType>,
|
||||
parameterNames: List<Name>?,
|
||||
returnType: KotlinType,
|
||||
builtIns: KotlinBuiltIns
|
||||
builtIns: KotlinBuiltIns,
|
||||
isSuspend: Boolean
|
||||
): SimpleType {
|
||||
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, parameterNames, returnType, builtIns)
|
||||
val classDescriptor = getKSuspendFunction(arguments.size - 1 /* return type */)
|
||||
val classDescriptor =
|
||||
if (isSuspend) getKSuspendFunction(arguments.size - 1 /* return type */) else getKFunction(arguments.size - 1 /* return type */)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
||||
}
|
||||
|
||||
@@ -117,7 +95,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
}
|
||||
|
||||
fun isCallableType(type: KotlinType): Boolean =
|
||||
type.isFunctionTypeOrSubtype || type.isSuspendFunctionType || isKCallableType(type)
|
||||
type.isFunctionTypeOrSubtype || type.isSuspendFunctionTypeOrSubtype || isKCallableType(type)
|
||||
|
||||
@JvmStatic
|
||||
fun isNumberedKPropertyOrKMutablePropertyType(type: KotlinType): Boolean =
|
||||
@@ -141,18 +119,20 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
hasFqName(descriptor, KotlinBuiltIns.FQ_NAMES.kProperty2)
|
||||
}
|
||||
|
||||
fun isNumberedKFunction(type: KotlinType): Boolean {
|
||||
fun isNumberedKFunctionOrKSuspendFunction(type: KotlinType): Boolean {
|
||||
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return false
|
||||
val shortName = descriptor.name.asString()
|
||||
|
||||
return (shortName.length > K_FUNCTION_PREFIX.length && shortName.startsWith(K_FUNCTION_PREFIX) || isKSuspendFunction(type)) &&
|
||||
return (shortName.length > K_FUNCTION_PREFIX.length && shortName.startsWith(K_FUNCTION_PREFIX) ||
|
||||
isNumberedKSuspendFunction(type)) &&
|
||||
DescriptorUtils.getFqName(descriptor).parent().toSafe() == KOTLIN_REFLECT_FQ_NAME
|
||||
}
|
||||
|
||||
fun isKSuspendFunction(type: KotlinType): Boolean {
|
||||
fun isNumberedKSuspendFunction(type: KotlinType): Boolean {
|
||||
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return false
|
||||
val shortName = descriptor.name.asString()
|
||||
return shortName.length > K_SUSPEND_FUNCTION_PREFIX.length && shortName.startsWith(K_SUSPEND_FUNCTION_PREFIX)
|
||||
return shortName.length > K_SUSPEND_FUNCTION_PREFIX.length && shortName.startsWith(K_SUSPEND_FUNCTION_PREFIX) &&
|
||||
DescriptorUtils.getFqName(descriptor).parent().toSafe() == KOTLIN_REFLECT_FQ_NAME
|
||||
}
|
||||
|
||||
private fun hasFqName(typeConstructor: TypeConstructor, fqName: FqNameUnsafe): Boolean {
|
||||
@@ -182,7 +162,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
val packageName = fqName.parent().toSafe()
|
||||
if (packageName == KOTLIN_REFLECT_FQ_NAME) {
|
||||
return shortName.startsWith("KFunction") // KFunctionN, KFunction
|
||||
|| shortName.startsWith("KSuspendFunction") // KPropertyN, KProperty
|
||||
|| shortName.startsWith("KSuspendFunction") // KSuspendFunctionN
|
||||
|| shortName.startsWith("KProperty") // KPropertyN, KProperty
|
||||
|| shortName.startsWith("KMutableProperty") // KMutablePropertyN, KMutableProperty
|
||||
|| shortName == "KCallable" || shortName == "KAnnotatedElement"
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.builtins
|
||||
@@ -58,6 +47,9 @@ private fun KotlinType.isTypeOrSubtypeOf(predicate: (KotlinType) -> Boolean): Bo
|
||||
val KotlinType.isFunctionTypeOrSubtype: Boolean
|
||||
get() = isTypeOrSubtypeOf { it.isFunctionType }
|
||||
|
||||
val KotlinType.isSuspendFunctionTypeOrSubtype: Boolean
|
||||
get() = isTypeOrSubtypeOf { it.isSuspendFunctionType }
|
||||
|
||||
val KotlinType.isBuiltinFunctionalTypeOrSubtype: Boolean
|
||||
get() = isTypeOrSubtypeOf { it.isBuiltinFunctionalType }
|
||||
|
||||
@@ -67,6 +59,9 @@ val KotlinType.isFunctionType: Boolean
|
||||
val KotlinType.isSuspendFunctionType: Boolean
|
||||
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction
|
||||
|
||||
val KotlinType.isFunctionOrSuspendFunctionType: Boolean
|
||||
get() = isFunctionType || isSuspendFunctionType
|
||||
|
||||
val KotlinType.isBuiltinFunctionalType: Boolean
|
||||
get() {
|
||||
val kind = constructor.declarationDescriptor?.getFunctionalClassKind()
|
||||
|
||||
+11
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -118,7 +118,6 @@ class FunctionClassDescriptor(
|
||||
result.add(KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, descriptor, arguments))
|
||||
}
|
||||
|
||||
|
||||
when (functionKind) {
|
||||
Kind.SuspendFunction -> // SuspendFunction$N<...> <: Function
|
||||
add(containingDeclaration, Name.identifier("Function"))
|
||||
@@ -128,17 +127,19 @@ class FunctionClassDescriptor(
|
||||
add(containingDeclaration, Name.identifier(functionKind.classNamePrefix))
|
||||
}
|
||||
|
||||
// For KFunction{n}, add corresponding numbered Function{n} class, e.g. Function2 for KFunction2
|
||||
if (functionKind == Kind.KFunction) {
|
||||
val numberedSupertypeKind = when (functionKind) {
|
||||
Kind.KFunction -> Kind.Function
|
||||
Kind.KSuspendFunction -> Kind.SuspendFunction
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
// For K{Suspend}Function{n}, add corresponding numbered {Suspend}Function{n} class, e.g. {Suspend}Function2 for {Suspend}KFunction2
|
||||
if (numberedSupertypeKind != null) {
|
||||
val packageView = containingDeclaration.containingDeclaration.getPackage(BUILT_INS_PACKAGE_FQ_NAME)
|
||||
val kotlinPackageFragment = packageView.fragments.filterIsInstance<BuiltInsPackageFragment>().first()
|
||||
|
||||
add(kotlinPackageFragment, Kind.Function.numberedClassName(arity))
|
||||
} else if (functionKind == Kind.KSuspendFunction) {
|
||||
val packageView = containingDeclaration.containingDeclaration.getPackage(BUILT_INS_PACKAGE_FQ_NAME)
|
||||
val kotlinPackageFragment = packageView.fragments.filterIsInstance<BuiltInsPackageFragment>().first()
|
||||
|
||||
add(kotlinPackageFragment, Kind.SuspendFunction.numberedClassName(arity))
|
||||
add(kotlinPackageFragment, numberedSupertypeKind.numberedClassName(arity))
|
||||
}
|
||||
|
||||
return result.toList()
|
||||
|
||||
Reference in New Issue
Block a user