fix KT-9652 Warning to specify expected type as Any? when it is already Any?
#KT-9652 Fixed
This commit is contained in:
@@ -286,6 +286,9 @@ public class DataFlowAnalyzer {
|
||||
return expressionType;
|
||||
}
|
||||
}
|
||||
else if (isIfExpression && context.expectedType != NO_EXPECTED_TYPE) {
|
||||
return expressionType;
|
||||
}
|
||||
else {
|
||||
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
|
||||
}
|
||||
|
||||
+33
@@ -114,6 +114,39 @@ fun testImplicitCoercion() {
|
||||
})
|
||||
}
|
||||
|
||||
fun fooWithAnyArg(<!UNUSED_PARAMETER!>arg<!>: Any) {}
|
||||
fun fooWithAnyNullableArg(<!UNUSED_PARAMETER!>arg<!>: Any?) {}
|
||||
|
||||
fun testCoercionToAny() {
|
||||
val d = 21
|
||||
val <!UNUSED_VARIABLE!>x1<!>: Any = if (1>2) 1 else 2.0
|
||||
val <!UNUSED_VARIABLE!>x2<!>: Any? = if (1>2) 1 else 2.0
|
||||
val <!UNUSED_VARIABLE!>x3<!>: Any? = if (1>2) 1 else (if (1>2) null else 2.0)
|
||||
|
||||
fooWithAnyArg(if (1>2) 1 else 2.0)
|
||||
fooWithAnyNullableArg(if (1>2) 1 else 2.0)
|
||||
fooWithAnyNullableArg(if (1>2) 1 else (if (1>2) null else 2.0))
|
||||
|
||||
val <!UNUSED_VARIABLE!>y1<!>: Any = when(d) { 1 -> 1.0 else -> 2.0 }
|
||||
val <!UNUSED_VARIABLE!>y2<!>: Any? = when(d) { 1 -> 1.0 else -> 2.0 }
|
||||
val <!UNUSED_VARIABLE!>y3<!>: Any? = when(d) { 1 -> 1.0; 2 -> null; else -> 2.0 }
|
||||
|
||||
fooWithAnyArg(when(d) { 1 -> 1.0 else -> 2.0 })
|
||||
fooWithAnyNullableArg(when(d) { 1 -> 1.0 else -> 2.0 })
|
||||
fooWithAnyNullableArg(when(d) { 1 -> 1.0; 2 -> null; else -> 2.0 })
|
||||
}
|
||||
|
||||
fun fooWithAnuNullableResult(s: String?, name: String, optional: Boolean): Any? {
|
||||
return if (s == null) {
|
||||
if (!optional) {
|
||||
throw java.lang.IllegalArgumentException("Parameter '$name' was not found in the request")
|
||||
}
|
||||
null
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(<!UNUSED_PARAMETER!>a<!>: Unit) {}
|
||||
|
||||
fun testStatementInExpressionContext() {
|
||||
|
||||
+4
@@ -6,9 +6,13 @@ package kt770_351_735 {
|
||||
public fun box(): kotlin.Int
|
||||
public fun doSmth(/*0*/ i: kotlin.Int): kotlin.Unit
|
||||
public fun foo(): kotlin.Unit
|
||||
public fun fooWithAnuNullableResult(/*0*/ s: kotlin.String?, /*1*/ name: kotlin.String, /*2*/ optional: kotlin.Boolean): kotlin.Any?
|
||||
public fun fooWithAnyArg(/*0*/ arg: kotlin.Any): kotlin.Unit
|
||||
public fun fooWithAnyNullableArg(/*0*/ arg: kotlin.Any?): kotlin.Unit
|
||||
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
public fun test1(): kotlin.Unit
|
||||
public fun test2(): kotlin.Unit
|
||||
public fun testCoercionToAny(): kotlin.Unit
|
||||
public fun testCoercionToUnit(): kotlin.Unit
|
||||
public fun testImplicitCoercion(): kotlin.Unit
|
||||
public fun testStatementInExpressionContext(): kotlin.Unit
|
||||
|
||||
Reference in New Issue
Block a user