Support local return in lambda without explicit return type
This commit is contained in:
@@ -596,7 +596,6 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetSimpleNameExpression> EXPRESSION_EXPECTED_PACKAGE_FOUND = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetReturnExpression> RETURN_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetReturnExpression> RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetReturnExpression> RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetDeclarationWithBody>
|
||||
NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_WITH_BODY);
|
||||
|
||||
-1
@@ -161,7 +161,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM,
|
||||
"Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
|
||||
MAP.put(RETURN_NOT_ALLOWED, "'return' is not allowed here");
|
||||
MAP.put(RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED, "'return' is only allowed in function literals that have return types specified explicitly");
|
||||
MAP.put(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE, "Projections are not allowed for immediate arguments of a supertype");
|
||||
MAP.put(LABEL_NAME_CLASH, "There is more than one label with such a name in this scope");
|
||||
MAP.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, "Expression expected, but a package name found");
|
||||
|
||||
@@ -84,6 +84,7 @@ public interface BindingContext {
|
||||
WritableSlice<JetTypeReference, JetType> TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<JetExpression, JetType> EXPRESSION_TYPE = new BasicWritableSlice<JetExpression, JetType>(DO_NOTHING);
|
||||
WritableSlice<JetExpression, JetType> EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice<JetExpression, JetType>(DO_NOTHING);
|
||||
WritableSlice<JetFunction, JetType> EXPECTED_RETURN_TYPE = new BasicWritableSlice<JetFunction, JetType>(DO_NOTHING);
|
||||
WritableSlice<JetExpression, DataFlowInfo> EXPRESSION_DATA_FLOW_INFO = new BasicWritableSlice<JetExpression, DataFlowInfo>(DO_NOTHING);
|
||||
WritableSlice<JetExpression, Approximation.Info> EXPRESSION_RESULT_APPROXIMATION = new BasicWritableSlice<JetExpression, Approximation.Info>(DO_NOTHING);
|
||||
WritableSlice<JetExpression, DataFlowInfo> DATAFLOW_INFO_AFTER_CONDITION = Slices.createSimpleSlice();
|
||||
|
||||
+5
-4
@@ -298,10 +298,11 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
// Type-check the body
|
||||
ExpressionTypingContext newContext = context.replaceScope(functionInnerScope)
|
||||
.replaceExpectedType(declaredReturnType != null
|
||||
? declaredReturnType
|
||||
: (expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE));
|
||||
JetType expectedType = declaredReturnType != null
|
||||
? declaredReturnType
|
||||
: (expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE);
|
||||
ExpressionTypingContext newContext = context.replaceScope(functionInnerScope).replaceExpectedType(expectedType);
|
||||
context.trace.record(EXPECTED_RETURN_TYPE, functionLiteral, expectedType);
|
||||
|
||||
JetType typeOfBodyExpression = components.expressionTypingServices.getBlockReturnedType(bodyExpression, COERCION_TO_UNIT, newContext).getType();
|
||||
|
||||
|
||||
+11
-12
@@ -465,7 +465,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
|
||||
}
|
||||
|
||||
expectedType = getFunctionExpectedReturnType(containingFunctionDescriptor, (JetElement) containingFunInfo.getSecond());
|
||||
expectedType = getFunctionExpectedReturnType(containingFunctionDescriptor, (JetElement) containingFunInfo.getSecond(), context);
|
||||
}
|
||||
else {
|
||||
// Outside a function
|
||||
@@ -476,17 +476,12 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
else if (labelTargetElement != null) {
|
||||
SimpleFunctionDescriptor functionDescriptor = context.trace.get(FUNCTION, labelTargetElement);
|
||||
if (functionDescriptor != null) {
|
||||
expectedType = getFunctionExpectedReturnType(functionDescriptor, labelTargetElement);
|
||||
expectedType = getFunctionExpectedReturnType(functionDescriptor, labelTargetElement, context);
|
||||
if (!InlineDescriptorUtils.checkNonLocalReturnUsage(functionDescriptor, expression, context.trace)) {
|
||||
// Qualified, non-local
|
||||
context.trace.report(RETURN_NOT_ALLOWED.on(expression));
|
||||
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
|
||||
}
|
||||
else if (expectedType == NO_EXPECTED_TYPE) {
|
||||
// expectedType is NO_EXPECTED_TYPE iff the return type of the corresponding function descriptor is not computed yet
|
||||
// our temporary policy is to prohibit returns in this case. It mostly applies to local returns in lambdas
|
||||
context.trace.report(RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED.on(expression));
|
||||
}
|
||||
}
|
||||
else {
|
||||
context.trace.report(NOT_A_RETURN_LABEL.on(expression, expression.getLabelName()));
|
||||
@@ -517,15 +512,19 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) {
|
||||
private static JetType getFunctionExpectedReturnType(
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull JetElement function,
|
||||
@NotNull ExpressionTypingContext context
|
||||
) {
|
||||
JetType expectedType;
|
||||
if (function instanceof JetFunction) {
|
||||
if (((JetFunction) function).getTypeReference() != null || ((JetFunction) function).hasBlockBody()) {
|
||||
JetFunction jetFunction = (JetFunction) function;
|
||||
expectedType = context.trace.get(EXPECTED_RETURN_TYPE, jetFunction);
|
||||
|
||||
if ((expectedType == null) && (jetFunction.getTypeReference() != null || jetFunction.hasBlockBody())) {
|
||||
expectedType = descriptor.getReturnType();
|
||||
}
|
||||
else {
|
||||
expectedType = TypeUtils.NO_EXPECTED_TYPE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
expectedType = descriptor.getReturnType();
|
||||
|
||||
@@ -8,10 +8,10 @@ fun unitEmptyReturn() : Unit {return}
|
||||
fun unitIntReturn() : Unit {return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>}
|
||||
fun unitUnitReturn() : Unit {return Unit}
|
||||
fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return<!>}
|
||||
fun test2() : Any = @a {<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@a 1<!>}
|
||||
fun test2() : Any = @a {return@a 1}
|
||||
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
|
||||
fun test4(): ()-> Unit = { <!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return@test4<!> }
|
||||
fun test5(): Any = @l{ <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l<!> }
|
||||
fun test5(): Any = @l{ return@l }
|
||||
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return 1<!>}
|
||||
|
||||
fun bbb() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
val flag = true
|
||||
|
||||
val a/*: () -> Comparable<out Any?>*/ = @l {
|
||||
return@l if (flag) "OK" else 4
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal val a: () -> kotlin.Comparable<out kotlin.Any?>
|
||||
internal val flag: kotlin.Boolean = true
|
||||
@@ -0,0 +1,15 @@
|
||||
val flag = true
|
||||
|
||||
// type of a was checked by txt
|
||||
val a/*: () -> Any*/ = @l { // commonSupertype(Int, Unit) = Any
|
||||
if (flag) return@l 4
|
||||
}
|
||||
|
||||
val b/*: () -> Int */ = @l {
|
||||
if (flag) return@l 4
|
||||
5
|
||||
}
|
||||
|
||||
val c/*: () -> Unit */ = @l {
|
||||
if (flag) <!UNUSED_EXPRESSION!>4<!>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal val a: () -> kotlin.Any
|
||||
internal val b: () -> kotlin.Int
|
||||
internal val c: () -> kotlin.Unit
|
||||
internal val flag: kotlin.Boolean = true
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
val flag = true
|
||||
|
||||
val a: () -> Int = @l {
|
||||
<!TYPE_MISMATCH!>if (flag) return@l 4<!>
|
||||
}
|
||||
|
||||
val b: () -> Unit = @l {
|
||||
if (flag) return@l <!CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
|
||||
}
|
||||
|
||||
val c: () -> Any = @l {
|
||||
if (flag) return@l 4
|
||||
}
|
||||
|
||||
val d: () -> Int = @l {
|
||||
if (flag) return@l 4
|
||||
5
|
||||
}
|
||||
|
||||
val e: () -> Int = @l {
|
||||
<!TYPE_MISMATCH!>if (flag) <!UNUSED_EXPRESSION!>4<!><!>
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
internal val a: () -> kotlin.Int
|
||||
internal val b: () -> kotlin.Unit
|
||||
internal val c: () -> kotlin.Any
|
||||
internal val d: () -> kotlin.Int
|
||||
internal val e: () -> kotlin.Int
|
||||
internal val flag: kotlin.Boolean = true
|
||||
@@ -0,0 +1,17 @@
|
||||
val flag = true
|
||||
|
||||
val a /*: (Int) -> String */ = @l {
|
||||
(i: Int) ->
|
||||
if (i == 0) return@l i.toString()
|
||||
|
||||
"Ok"
|
||||
}
|
||||
|
||||
fun <T> foo(f: (Int) -> T): T = f(0)
|
||||
|
||||
val b /*:String */ = foo {
|
||||
(i) ->
|
||||
if (i == 0) return@foo i.toString()
|
||||
|
||||
"Ok"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal val a: (kotlin.Int) -> kotlin.String
|
||||
internal val b: kotlin.String
|
||||
internal val flag: kotlin.Boolean = true
|
||||
internal fun </*0*/ T> foo(/*0*/ f: (kotlin.Int) -> T): T
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun test2(a: Int) {
|
||||
val x = run @f{
|
||||
if (a > 0) <!RETURN_NOT_ALLOWED!>return<!>
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
|
||||
return@f 1
|
||||
}
|
||||
x: Int
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun test2() {
|
||||
val x = run @f{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>}
|
||||
val x = run @f{return@f 1}
|
||||
x: Int
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
fun test() {
|
||||
val x = run(@f{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>})
|
||||
val x = run(@f{return@f 1})
|
||||
x: Int
|
||||
}
|
||||
|
||||
|
||||
fun test1() {
|
||||
val x = run(@l{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 1<!>})
|
||||
val x = run(@l{return@l 1})
|
||||
x: Int
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ fun test() {
|
||||
if (a > 0) return "2"
|
||||
return@local "3"
|
||||
}
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
|
||||
return@f 1
|
||||
}
|
||||
x: Int
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
fun test() {
|
||||
val x = run @f{
|
||||
run @ff {
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ff "2"<!>
|
||||
return@ff "2"
|
||||
}
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
|
||||
return@f 1
|
||||
}
|
||||
x: Int
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test(a: Int) {
|
||||
run @f{
|
||||
if (a > 0) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f<!>
|
||||
else <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
|
||||
if (a > 0) <!RETURN_TYPE_MISMATCH!>return@f<!>
|
||||
else return@f 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class A
|
||||
val flag = true
|
||||
|
||||
val a /*: () -> A?*/ = @l {
|
||||
if (flag) return@l null
|
||||
|
||||
A()
|
||||
}
|
||||
|
||||
val b /*: () -> A?*/ = @l {
|
||||
if (flag) return@l null
|
||||
|
||||
return@l A()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
internal val a: () -> A?
|
||||
internal val b: () -> A?
|
||||
internal val flag: kotlin.Boolean = true
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
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
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
fun test(a: Int) {
|
||||
val x = run @f{
|
||||
if (a > 0) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f<!>
|
||||
else <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f Unit<!>
|
||||
if (a > 0) <!RETURN_TYPE_MISMATCH!>return@f<!>
|
||||
else return@f Unit
|
||||
}
|
||||
x: Unit
|
||||
}
|
||||
|
||||
fun run<T>(f: () -> T): T { return f() }
|
||||
fun run<T>(f: () -> T): T { return f() }
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun listOf<T>(): List<T> = null!!
|
||||
fun listOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
|
||||
|
||||
val flag = true
|
||||
|
||||
val a: () -> List<Int> = @l {
|
||||
if (flag) return@l listOf()
|
||||
listOf(5)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal val a: () -> kotlin.List<kotlin.Int>
|
||||
internal val flag: kotlin.Boolean = true
|
||||
internal fun </*0*/ T> listOf(): kotlin.List<T>
|
||||
internal fun </*0*/ T> listOf(/*0*/ vararg values: T /*kotlin.Array<out T>*/): kotlin.List<T>
|
||||
+1
-1
@@ -5,7 +5,7 @@ trait C: A
|
||||
|
||||
fun test(a: C, b: B) {
|
||||
val x = run @f{
|
||||
if (a != b) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f a<!>
|
||||
if (a != b) return@f a
|
||||
b
|
||||
}
|
||||
x: A
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!>: (T) -> R): List<R> = null!!
|
||||
fun listOf<T>(): List<T> = null!!
|
||||
fun listOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
|
||||
|
||||
fun commonSystemFailed(a: List<Int>) {
|
||||
a.map {
|
||||
if (it == 0) return@map listOf(it)
|
||||
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>listOf<!>()
|
||||
}
|
||||
a.map {
|
||||
if (it == 0) return@map <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>listOf<!>()
|
||||
listOf(it)
|
||||
}
|
||||
a.map {
|
||||
if (it == 0) listOf()
|
||||
else listOf(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun commonSystemFailed(/*0*/ a: kotlin.List<kotlin.Int>): kotlin.Unit
|
||||
internal fun </*0*/ T> listOf(): kotlin.List<T>
|
||||
internal fun </*0*/ T> listOf(/*0*/ vararg values: T /*kotlin.Array<out T>*/): kotlin.List<T>
|
||||
internal fun </*0*/ T, /*1*/ R> kotlin.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
|
||||
@@ -0,0 +1,17 @@
|
||||
// KT-6822 Smart cast doesn't work inside local returned expression in lambda
|
||||
|
||||
val a /* :(Int?) -> Int? */ = @l { (it: Int?) -> // but must be (Int?) -> Int
|
||||
if (it != null) return@l it
|
||||
5
|
||||
}
|
||||
|
||||
fun <R> let(<!UNUSED_PARAMETER!>f<!>: (Int?) -> R): R = null!!
|
||||
|
||||
val b /*: Int? */ = let { // but must be Int
|
||||
if (it != null) return@let it
|
||||
5
|
||||
}
|
||||
|
||||
val c /*: Int*/ = let {
|
||||
if (it != null) <!DEBUG_INFO_SMARTCAST!>it<!> else 5
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal val a: (kotlin.Int?) -> kotlin.Int?
|
||||
internal val b: kotlin.Int?
|
||||
internal val c: kotlin.Int
|
||||
internal fun </*0*/ R> let(/*0*/ f: (kotlin.Int?) -> R): R
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// KT-6822 Smart cast doesn't work inside local returned expression in lambda
|
||||
|
||||
val a : (Int?) -> Int = @l {
|
||||
if (it != null) return@l <!DEBUG_INFO_SMARTCAST!>it<!>
|
||||
5
|
||||
}
|
||||
|
||||
fun <R> let(<!UNUSED_PARAMETER!>f<!>: (Int?) -> R): R = null!!
|
||||
|
||||
val b: Int = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>let<!> {
|
||||
if (it != null) return@let it
|
||||
5
|
||||
}
|
||||
|
||||
val c: Int = let {
|
||||
if (it != null) <!DEBUG_INFO_SMARTCAST!>it<!> else 5
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal val a: (kotlin.Int?) -> kotlin.Int
|
||||
internal val b: kotlin.Int
|
||||
internal val c: kotlin.Int
|
||||
internal fun </*0*/ R> let(/*0*/ f: (kotlin.Int?) -> R): R
|
||||
@@ -0,0 +1,10 @@
|
||||
package m
|
||||
|
||||
trait Element
|
||||
|
||||
fun test(handlers: Map<String, Element.()->Unit>) {
|
||||
|
||||
handlers.getOrElse("name", @l { return@l <!NULL_FOR_NONNULL_TYPE!>null<!> })
|
||||
}
|
||||
|
||||
fun <K,V> Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue")
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
package m {
|
||||
internal fun test(/*0*/ handlers: kotlin.Map<kotlin.String, m.Element.() -> kotlin.Unit>): kotlin.Unit
|
||||
internal fun </*0*/ K, /*1*/ V> kotlin.Map<K, V>.getOrElse(/*0*/ key: K, /*1*/ defaultValue: () -> V): V
|
||||
|
||||
internal trait Element {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package n
|
||||
|
||||
//+JDK
|
||||
import java.util.*
|
||||
|
||||
fun expected<T>(t: T, <!UNUSED_PARAMETER!>f<!>: () -> T) : T = t
|
||||
|
||||
fun test(arrayList: ArrayList<Int>, list: List<Int>) {
|
||||
val <!UNUSED_VARIABLE!>t<!> = expected(arrayList, @l {return@l list.reverse() })
|
||||
}
|
||||
|
||||
fun <T> List<T>.reverse() : List<T> = this
|
||||
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
package n {
|
||||
internal fun </*0*/ T> expected(/*0*/ t: T, /*1*/ f: () -> T): T
|
||||
internal fun test(/*0*/ arrayList: java.util.ArrayList<kotlin.Int>, /*1*/ list: kotlin.List<kotlin.Int>): kotlin.Unit
|
||||
internal fun </*0*/ T> kotlin.List<T>.reverse(): kotlin.List<T>
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
fun inlineCallExplicitError(): String {
|
||||
inlineFun @lamba {
|
||||
if (true) {
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@lamba 2<!>
|
||||
return@lamba 2
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public inline fun <reified T> Array(n: Int, block: (Int) -> T): Array<T> = null!
|
||||
fun test() {
|
||||
val ints = Array<Int?>(2, { null })
|
||||
ints.forEach @lit {
|
||||
if (it == null) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return @lit<!>
|
||||
if (it == null) return @lit
|
||||
use(<!DEBUG_INFO_SMARTCAST!>it<!> + 5)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package kt411
|
||||
fun f() {
|
||||
invoker(
|
||||
@l{
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 11<!> // expects Function, but should expect Int
|
||||
return@l 11 // expects Function, but should expect Int
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ fun t1() {
|
||||
fun t2() : String {
|
||||
val <!UNUSED_VARIABLE!>g<!> : ()-> Int = @l{
|
||||
if (true) {
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l 1<!>
|
||||
return@l 1
|
||||
}
|
||||
<!RETURN_NOT_ALLOWED!>return "s"<!>
|
||||
}
|
||||
@@ -37,7 +37,7 @@ fun t3() : String {
|
||||
else {
|
||||
<!RETURN_NOT_ALLOWED!>return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!><!>
|
||||
}
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED, UNREACHABLE_CODE!>return@l 0<!>
|
||||
<!UNREACHABLE_CODE!>return@l 0<!>
|
||||
}
|
||||
)
|
||||
invoker(
|
||||
@@ -55,7 +55,7 @@ fun t3() : String {
|
||||
|
||||
fun t4() : Int {
|
||||
val <!UNUSED_VARIABLE!>h<!> : ()-> String = @l{
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l "a"<!>
|
||||
return@l "a"
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>g<!> : ()-> String = @l{ () : String ->
|
||||
return@l "a"
|
||||
|
||||
@@ -4581,6 +4581,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("returnNullWithReturn.kt")
|
||||
public void testReturnNullWithReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/returnNullWithReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unusedLiteral.kt")
|
||||
public void testUnusedLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt");
|
||||
@@ -4619,6 +4625,30 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfInReturnedExpression.kt")
|
||||
public void testIfInReturnedExpression() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/IfInReturnedExpression.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfWithoutElse.kt")
|
||||
public void testIfWithoutElse() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfWithoutElseWithExplicitType.kt")
|
||||
public void testIfWithoutElseWithExplicitType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LambdaWithParameter.kt")
|
||||
public void testLambdaWithParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalAndNonLocalReturnInLambda.kt")
|
||||
public void testLocalAndNonLocalReturnInLambda() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LocalAndNonLocalReturnInLambda.kt");
|
||||
@@ -4661,12 +4691,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnNull.kt")
|
||||
public void testLocalReturnNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnUnit.kt")
|
||||
public void testLocalReturnUnit() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnWithExpectedType.kt")
|
||||
public void testLocalReturnWithExpectedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExpectedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnsWithExplicitReturnType.kt")
|
||||
public void testLocalReturnsWithExplicitReturnType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.kt");
|
||||
@@ -4678,6 +4720,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/MixedReturnsFromLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoCommonSystem.kt")
|
||||
public void testNoCommonSystem() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/NoCommonSystem.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCast.kt")
|
||||
public void testSmartCast() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCastWithExplicitType.kt")
|
||||
public void testSmartCastWithExplicitType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/return/SmartCastWithExplicitType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5405,6 +5465,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inferInFunctionLiteralsWithReturn.kt")
|
||||
public void testInferInFunctionLiteralsWithReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/inferInFunctionLiteralsWithReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt1293.kt")
|
||||
public void testKt1293() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/kt1293.kt");
|
||||
|
||||
@@ -6,7 +6,7 @@ fun unitEmptyReturn() : Unit {return}
|
||||
fun unitIntReturn() : Unit {return <error>1</error>}
|
||||
fun unitUnitReturn() : Unit {return Unit}
|
||||
fun test1() : Any = { <error>return</error> }
|
||||
fun test2() : Any = @a {<error>return@a 1</error>}
|
||||
fun test2() : Any = @a {return@a 1}
|
||||
fun test3() : Any { <error>return</error> }
|
||||
|
||||
fun bbb() {
|
||||
|
||||
Reference in New Issue
Block a user