KT-5068: Introduce a special diagnostic message for TYPE_MISMATCH cases such as 'fun f(): Int = { 1 }'.

This commit is contained in:
Dmitry Petrov
2016-05-20 16:27:03 +03:00
parent 8b06d919b4
commit 968ed3f091
8 changed files with 108 additions and 2 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ fun intBlock() : Int {return 1}
fun intBlock1() : Int {<!UNUSED_EXPRESSION!>1<!><!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun intString(): Int = <!TYPE_MISMATCH!>"s"<!>
fun intFunctionLiteral(): Int = <!TYPE_MISMATCH!>{ 10 }<!>
fun intFunctionLiteral(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 10 }<!>
fun blockReturnUnitMismatch() : Int {<!RETURN_TYPE_MISMATCH!>return<!>}
fun blockReturnValueTypeMismatch() : Int {return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>3.4<!>}
@@ -0,0 +1,36 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// KT-5068 Add special error for scala-like syntax 'fun foo(): Int = { 1 }'
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
fun outer() {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
}
class Outer {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
class Nested {
fun test1(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
fun test2(): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
val test3: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ <!RETURN_NOT_ALLOWED!>return 1<!> }<!>
val test4: () -> Int = fun (): Int = <!TYPE_MISMATCH_DUE_TO_EQUALS_LAMBDA_IN_FUN!>{ 1 }<!>
fun test5(): Int { return <!TYPE_MISMATCH!>{ 1 }<!> }
fun test6(): Int = <!TYPE_MISMATCH!>fun (): Int = 1<!>
}
}
@@ -0,0 +1,35 @@
package
public val test3: () -> kotlin.Int
public val test4: () -> kotlin.Int
public fun outer(): kotlin.Unit
public fun test1(): kotlin.Int
public fun test2(): kotlin.Int
public fun test5(): kotlin.Int
public fun test6(): kotlin.Int
public final class Outer {
public constructor Outer()
public final val test3: () -> kotlin.Int
public final val test4: () -> kotlin.Int
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 final fun test1(): kotlin.Int
public final fun test2(): kotlin.Int
public final fun test5(): kotlin.Int
public final fun test6(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final class Nested {
public constructor Nested()
public final val test3: () -> kotlin.Int
public final val test4: () -> kotlin.Int
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 final fun test1(): kotlin.Int
public final fun test2(): kotlin.Int
public final fun test5(): kotlin.Int
public final fun test6(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}