Implicit Nothing return type is now deprecated
This commit is contained in:
@@ -694,6 +694,8 @@ public interface Errors {
|
|||||||
|
|
||||||
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory0<PsiElement> IMPLICIT_NOTHING_RETURN_TYPE = DiagnosticFactory0.create(WARNING);
|
||||||
|
|
||||||
// Context tracking
|
// Context tracking
|
||||||
|
|
||||||
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR);
|
||||||
|
|||||||
+1
@@ -525,6 +525,7 @@ public class DefaultErrorMessages {
|
|||||||
RENDER_TYPE);
|
RENDER_TYPE);
|
||||||
MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type kotlin.Boolean, but is of type {0}", RENDER_TYPE);
|
MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type kotlin.Boolean, but is of type {0}", RENDER_TYPE);
|
||||||
MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE);
|
MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE);
|
||||||
|
MAP.put(IMPLICIT_NOTHING_RETURN_TYPE, "''Nothing'' return type needs to be specified explicitly");
|
||||||
MAP.put(EXPECTED_CONDITION, "Expected condition of type kotlin.Boolean");
|
MAP.put(EXPECTED_CONDITION, "Expected condition of type kotlin.Boolean");
|
||||||
|
|
||||||
MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE);
|
MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.lexer.JetTokens;
|
|||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.types.*;
|
import org.jetbrains.kotlin.types.*;
|
||||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -641,6 +642,9 @@ public class DeclarationsChecker {
|
|||||||
if (!function.hasBody() && !hasAbstractModifier) {
|
if (!function.hasBody() && !hasAbstractModifier) {
|
||||||
trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
|
trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
|
||||||
}
|
}
|
||||||
|
if (TypeUtilsKt.isNothing(functionDescriptor.getReturnType()) && !function.hasDeclaredReturnType()) {
|
||||||
|
trace.report(IMPLICIT_NOTHING_RETURN_TYPE.on(function.getNameIdentifier() != null ? function.getNameIdentifier() : function));
|
||||||
|
}
|
||||||
checkFunctionExposedType(function, functionDescriptor);
|
checkFunctionExposedType(function, functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
fun a(): IntArray? = null
|
fun a(): IntArray? = null
|
||||||
|
|
||||||
fun b() = throw Exception()
|
fun b(): Nothing = throw Exception()
|
||||||
|
|
||||||
fun foo(): IntArray = a() ?: b()
|
fun foo(): IntArray = a() ?: b()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
fun a(): String? = null
|
fun a(): String? = null
|
||||||
|
|
||||||
fun b() = throw Exception()
|
fun b(): Nothing = throw Exception()
|
||||||
|
|
||||||
fun foo(): String = a() ?: b()
|
fun foo(): String = a() ?: b()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ fun testCommasAndWhitespaces() {
|
|||||||
<!UNREACHABLE_CODE!>bar(<!> 1 , todo() , <!UNREACHABLE_CODE!>"" )<!>
|
<!UNREACHABLE_CODE!>bar(<!> 1 , todo() , <!UNREACHABLE_CODE!>"" )<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ fun test3() {
|
|||||||
<!UNREACHABLE_CODE!>bar(<!>11, l@(todo()/*comment*/), <!UNREACHABLE_CODE!>"")<!>
|
<!UNREACHABLE_CODE!>bar(<!>11, l@(todo()/*comment*/), <!UNREACHABLE_CODE!>"")<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
|
|
||||||
fun bar(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String, <!UNUSED_PARAMETER!>a<!>: Any) {}
|
fun bar(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String, <!UNUSED_PARAMETER!>a<!>: Any) {}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,4 +8,4 @@ fun testInvokeWithLambda() {
|
|||||||
todo()<!UNREACHABLE_CODE!>(1){ 42 }<!>
|
todo()<!UNREACHABLE_CODE!>(1){ 42 }<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
+1
-1
@@ -8,4 +8,4 @@ fun test12() {
|
|||||||
todo()<!UNNECESSARY_SAFE_CALL!>?.<!><!UNREACHABLE_CODE!>bar(1)<!>
|
todo()<!UNNECESSARY_SAFE_CALL!>?.<!><!UNREACHABLE_CODE!>bar(1)<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
Vendored
+1
-1
@@ -14,7 +14,7 @@ fun test3() {
|
|||||||
<!UNREACHABLE_CODE!>bar()<!>
|
<!UNREACHABLE_CODE!>bar()<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun throwNPE() = null!!
|
fun throwNPE(): Nothing = null!!
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
operator fun plus(<!UNUSED_PARAMETER!>a<!>: A): Nothing = throw Exception()
|
operator fun plus(<!UNUSED_PARAMETER!>a<!>: A): Nothing = throw Exception()
|
||||||
|
|||||||
+1
-1
@@ -37,4 +37,4 @@ fun testArrayPlusAssign(array: Array<Any>) {
|
|||||||
array[1] <!UNREACHABLE_CODE!>+=<!> todo()
|
array[1] <!UNREACHABLE_CODE!>+=<!> todo()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
+1
-1
@@ -15,4 +15,4 @@ fun testPlusAssign() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
Vendored
+1
-1
@@ -35,5 +35,5 @@ fun returnInBinary2(): Boolean {
|
|||||||
(return true) <!UNREACHABLE_CODE!>|| (return false)<!>
|
(return true) <!UNREACHABLE_CODE!>|| (return false)<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
fun bar() {}
|
fun bar() {}
|
||||||
+1
-1
@@ -10,4 +10,4 @@ fun testArgumentInVariableAsFunctionCall(f: (Any) -> Unit) {
|
|||||||
f<!UNREACHABLE_CODE!>(<!>todo()<!UNREACHABLE_CODE!>)<!>
|
f<!UNREACHABLE_CODE!>(<!>todo()<!UNREACHABLE_CODE!>)<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
+1
-1
@@ -21,4 +21,4 @@ fun unreachable4(array: Array<Any>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun bar(a: Any) {}
|
fun bar(a: Any) {}
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
|
|||||||
+1
-1
@@ -8,5 +8,5 @@ fun testIf1(b: Boolean) {
|
|||||||
bar()
|
bar()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
fun bar() {}
|
fun bar() {}
|
||||||
Vendored
+1
-1
@@ -10,4 +10,4 @@ fun testCompound1() {
|
|||||||
<!UNREACHABLE_CODE!>(<!>todo() <!UNREACHABLE_CODE!>* "")[1]<!>
|
<!UNREACHABLE_CODE!>(<!>todo() <!UNREACHABLE_CODE!>* "")[1]<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
Vendored
+1
-1
@@ -32,5 +32,5 @@ fun testFunctionDefaultArgument() {
|
|||||||
|
|
||||||
open class Foo(i: Int) {}
|
open class Foo(i: Int) {}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
fun bar() {}
|
fun bar() {}
|
||||||
+1
-1
@@ -17,5 +17,5 @@ fun testDoWhile() {
|
|||||||
<!UNREACHABLE_CODE!>bar()<!>
|
<!UNREACHABLE_CODE!>bar()<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
fun bar() {}
|
fun bar() {}
|
||||||
+1
-1
@@ -2,4 +2,4 @@ fun testReturn() {
|
|||||||
<!UNREACHABLE_CODE!>return<!> todo()
|
<!UNREACHABLE_CODE!>return<!> todo()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
+1
-1
@@ -12,4 +12,4 @@ fun testPostfixSpecial() {
|
|||||||
todo()<!UNNECESSARY_NOT_NULL_ASSERTION, UNREACHABLE_CODE!>!!<!>
|
todo()<!UNNECESSARY_NOT_NULL_ASSERTION, UNREACHABLE_CODE!>!!<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun todo() = throw Exception()
|
fun todo(): Nothing = throw Exception()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>foo<!>() = throw Exception()
|
||||||
|
|
||||||
|
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>bar<!>() = null!!
|
||||||
|
|
||||||
|
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>baz<!>() = bar()
|
||||||
|
|
||||||
|
fun gav(): Any = null!!
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun bar(): kotlin.Nothing
|
||||||
|
public fun baz(): kotlin.Nothing
|
||||||
|
public fun foo(): kotlin.Nothing
|
||||||
|
public fun gav(): kotlin.Any
|
||||||
+1
-1
@@ -45,4 +45,4 @@ fun test4() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fail() = throw Exception()
|
fun fail(): Nothing = throw Exception()
|
||||||
@@ -19,4 +19,4 @@ fun foo1(e: PsiElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//from library
|
//from library
|
||||||
fun println(any: Any?) = throw Exception("$any")
|
fun println(any: Any?): Nothing = throw Exception("$any")
|
||||||
@@ -265,6 +265,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("implicitNothing.kt")
|
||||||
|
public void testImplicitNothing() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/implicitNothing.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("IncDec.kt")
|
@TestMetadata("IncDec.kt")
|
||||||
public void testIncDec() throws Exception {
|
public void testIncDec() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/IncDec.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/IncDec.kt");
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ package kotlin
|
|||||||
// This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test
|
// This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test
|
||||||
// see StdLibTestBase.removeAdHocAssertions
|
// see StdLibTestBase.removeAdHocAssertions
|
||||||
|
|
||||||
fun fail(message: String? = null) = throw Exception(message)
|
fun fail(message: String? = null): Nothing = throw Exception(message)
|
||||||
|
|
||||||
fun assertEquals<T>(expected: T, actual: T, message: String? = null) {
|
fun assertEquals<T>(expected: T, actual: T, message: String? = null) {
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
|
|||||||
Reference in New Issue
Block a user