Fix type inference issues for 'if' and 'when'.
Use 'expectedType' (when present) as an explicit type argument for a special construct call. Unfortunately, this approach can't be used for elvis due to other elvis-related inference hacks. Fixes KT-10807, KT-10811. This also affects KT-6189: now we can infer proper type for 'if'. If type inference for special call failed, and we found no type errors in sub-expressions, report TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT error. This (and the hack above) fixes KT-10809: code no longer compiles.
This commit is contained in:
+2
-2
@@ -181,8 +181,8 @@ fun returnFunctionLiteral(a: Any?): Function0<Int> {
|
||||
else return { -> 1 }
|
||||
}
|
||||
|
||||
fun returnFunctionLiteralDoesntWork(a: Any?): Function0<Int> =
|
||||
if (a is Int) <!TYPE_MISMATCH!>{ -> a }<!>
|
||||
fun returnFunctionLiteralExpressionBody(a: Any?): Function0<Int> =
|
||||
if (a is Int) { -> <!DEBUG_INFO_SMARTCAST!>a<!> }
|
||||
else { -> 1 }
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public fun illegalWhenBody(/*0*/ a: kotlin.Any): kotlin.Int
|
||||
public fun mergeSmartCasts(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
public fun returnFunctionLiteral(/*0*/ a: kotlin.Any?): () -> kotlin.Int
|
||||
public fun returnFunctionLiteralBlock(/*0*/ a: kotlin.Any?): () -> kotlin.Int
|
||||
public fun returnFunctionLiteralDoesntWork(/*0*/ a: kotlin.Any?): () -> kotlin.Int
|
||||
public fun returnFunctionLiteralExpressionBody(/*0*/ a: kotlin.Any?): () -> kotlin.Int
|
||||
public fun toInt(/*0*/ i: kotlin.Int?): kotlin.Int
|
||||
public fun vars(/*0*/ a: kotlin.Any?): kotlin.Unit
|
||||
|
||||
|
||||
Reference in New Issue
Block a user