diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index 1501bc1130c..569bfbe7eb4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -349,6 +349,7 @@ class DeclarationsChecker( if (memberDescriptor.kind != CallableMemberDescriptor.Kind.DECLARATION) continue val member = DescriptorToSourceUtils.descriptorToDeclaration(memberDescriptor) as? KtFunction if (member != null && memberDescriptor is FunctionDescriptor) { + checkImplicitCallableType(member, memberDescriptor) checkFunctionExposedType(member, memberDescriptor) checkVarargParameters(trace, memberDescriptor) } @@ -689,14 +690,15 @@ class DeclarationsChecker( if (!hasBody && !hasAbstractModifier && !hasExternalModifier && !inTrait) { trace.report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(function, functionDescriptor)) } - return } - if (!function.hasBody() && !hasAbstractModifier && !hasExternalModifier) { - trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor)) + else /* top-level only */ { + if (!function.hasBody() && !hasAbstractModifier && !hasExternalModifier) { + trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor)) + } + checkImplicitCallableType(function, functionDescriptor) + checkFunctionExposedType(function, functionDescriptor) + checkVarargParameters(trace, functionDescriptor) } - checkImplicitCallableType(function, functionDescriptor) - checkFunctionExposedType(function, functionDescriptor) - checkVarargParameters(trace, functionDescriptor) } private fun checkImplicitCallableType(declaration: KtCallableDeclaration, descriptor: CallableDescriptor) { diff --git a/compiler/testData/codegen/box/typeMapping/kt3863.kt b/compiler/testData/codegen/box/typeMapping/kt3863.kt index 5fa48876a48..21b6b4acd63 100644 --- a/compiler/testData/codegen/box/typeMapping/kt3863.kt +++ b/compiler/testData/codegen/box/typeMapping/kt3863.kt @@ -4,7 +4,7 @@ import kotlin.reflect.KProperty class NotImplemented(){ operator fun getValue(thisRef: Any?, prop: KProperty<*>): T = notImplemented() - operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: T) = notImplemented() + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: T): Nothing = notImplemented() } fun notImplemented() : Nothing = notImplemented() diff --git a/compiler/testData/codegen/properties/privateClassPropertyAccessors.kt b/compiler/testData/codegen/properties/privateClassPropertyAccessors.kt index 21e4230aa96..a001bf6b220 100644 --- a/compiler/testData/codegen/properties/privateClassPropertyAccessors.kt +++ b/compiler/testData/codegen/properties/privateClassPropertyAccessors.kt @@ -27,7 +27,7 @@ class C { object Delegate { - operator fun getValue(x: C, p: KProperty<*>) = throw AssertionError() + operator fun getValue(x: C, p: KProperty<*>): Nothing = throw AssertionError() - operator fun setValue(x: C, p: KProperty<*>, value: Int) = throw AssertionError() + operator fun setValue(x: C, p: KProperty<*>, value: Int): Nothing = throw AssertionError() } diff --git a/compiler/testData/diagnostics/tests/implicitIntersection.kt b/compiler/testData/diagnostics/tests/implicitIntersection.kt index e3103ae5553..ea537a4f67d 100644 --- a/compiler/testData/diagnostics/tests/implicitIntersection.kt +++ b/compiler/testData/diagnostics/tests/implicitIntersection.kt @@ -14,6 +14,8 @@ class My(b: B) { val x = if (b is A && b is C) b else null // Ok: given explicitly val y: C? = if (b is A && b is C) b else null + // Error! + fun foo(b: B) = if (b is A && b is C) b else null } fun bar(b: B): String { diff --git a/compiler/testData/diagnostics/tests/implicitIntersection.txt b/compiler/testData/diagnostics/tests/implicitIntersection.txt index 7589f7213f4..048080bc5a4 100644 --- a/compiler/testData/diagnostics/tests/implicitIntersection.txt +++ b/compiler/testData/diagnostics/tests/implicitIntersection.txt @@ -28,6 +28,7 @@ public final class My { public final val x: {C & A & B}? public final val y: C? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ b: B): {C & A & B}? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/compiler/testData/diagnostics/tests/implicitNothing.kt b/compiler/testData/diagnostics/tests/implicitNothing.kt index 68c27bb6e63..ef43da2e8ea 100644 --- a/compiler/testData/diagnostics/tests/implicitNothing.kt +++ b/compiler/testData/diagnostics/tests/implicitNothing.kt @@ -16,3 +16,21 @@ fun check() { // Unreachable / unused, but not implicit Nothing val x = null!! } + +class Klass { + fun bar() = null!! + + val y = null!! + + init { + fun local() = bar() + // Should be unreachable: see KT-5311 + val z = null!! + } + + fun foo() { + fun local() = bar() + + val x = y + } +} diff --git a/compiler/testData/diagnostics/tests/implicitNothing.txt b/compiler/testData/diagnostics/tests/implicitNothing.txt index 185cac036d7..3a4daf0cdbd 100644 --- a/compiler/testData/diagnostics/tests/implicitNothing.txt +++ b/compiler/testData/diagnostics/tests/implicitNothing.txt @@ -7,3 +7,13 @@ public fun baz(): kotlin.Nothing public fun check(): kotlin.Unit public fun foo(): kotlin.Nothing public fun gav(): kotlin.Any + +public final class Klass { + public constructor Klass() + public final val y: kotlin.Nothing + public final fun bar(): kotlin.Nothing + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classMembers/DelegatedProperty.kt b/compiler/testData/loadJava/compiledKotlin/annotations/classMembers/DelegatedProperty.kt index d16b8591705..a88cca51d89 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/classMembers/DelegatedProperty.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classMembers/DelegatedProperty.kt @@ -6,6 +6,6 @@ annotation class Anno class Class { @Anno val x: Int by object { - operator fun getValue(thiz: Class, data: KProperty<*>) = null!! + operator fun getValue(thiz: Class, data: KProperty<*>): Nothing = null!! } } diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/packageMembers/DelegatedProperty.kt b/compiler/testData/loadJava/compiledKotlin/annotations/packageMembers/DelegatedProperty.kt index 282ab61f3b2..8f473f25587 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/packageMembers/DelegatedProperty.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/packageMembers/DelegatedProperty.kt @@ -8,5 +8,5 @@ import kotlin.reflect.KProperty annotation class Anno @Anno val x: Int by object { - operator fun getValue(thiz: Any?, data: KProperty<*>) = null!! + operator fun getValue(thiz: Any?, data: KProperty<*>): Nothing = null!! } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt index ff6eaf263a7..f48c274099b 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt @@ -213,7 +213,7 @@ private class EnhancedTypeAnnotations(private val fqNameToMatch: FqName) : Annot } private object EnhancedTypeAnnotationDescriptor : AnnotationDescriptor { - private fun throwError() = error("No methods should be called on this descriptor. Only its presence matters") + private fun throwError(): Nothing = error("No methods should be called on this descriptor. Only its presence matters") override fun getType() = throwError() override fun getAllValueArguments() = throwError() override fun getSource() = throwError() diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt index 3a497422c9e..644f470ac51 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt @@ -76,6 +76,6 @@ internal object EmptyContainerForLocal : KDeclarationContainerImpl() { override fun getFunctions(name: Name): Collection = fail() - private fun fail() = throw KotlinReflectionInternalError("Introspecting local functions, lambdas and anonymous functions " + + private fun fail(): Nothing = throw KotlinReflectionInternalError("Introspecting local functions, lambdas and anonymous functions " + "is not yet fully supported in Kotlin reflection") } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt index 631dc89bfc1..e0c370940e0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -440,9 +440,9 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour } } - private fun exception(msg: String) = throw EvaluateExceptionUtil.createEvaluateException(msg) + private fun exception(msg: String): Nothing = throw EvaluateExceptionUtil.createEvaluateException(msg) - private fun exception(e: Throwable) = throw EvaluateExceptionUtil.createEvaluateException(e) + private fun exception(e: Throwable): Nothing = throw EvaluateExceptionUtil.createEvaluateException(e) // contextFile must be NotNull when analyzeInlineFunctions = true private fun KtFile.checkForErrors(analyzeInlineFunctions: Boolean = false, contextFile: KtFile? = null): ExtendedAnalysisResult { diff --git a/idea/testData/intentions/convertFunctionToProperty/nothingFun.kt b/idea/testData/intentions/convertFunctionToProperty/nothingFun.kt index 14a59b12a11..fd544fcdea6 100644 --- a/idea/testData/intentions/convertFunctionToProperty/nothingFun.kt +++ b/idea/testData/intentions/convertFunctionToProperty/nothingFun.kt @@ -1,7 +1,7 @@ // WITH_RUNTIME // IS_APPLICABLE: false class A(val n: Int) { - fun foo() = throw Exception("foo") + fun foo(): Nothing = throw Exception("foo") } fun test() {