Test for using dynamic types in type inference
This commit is contained in:
@@ -269,7 +269,8 @@ public class DataFlowUtils {
|
||||
@Nullable
|
||||
public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) {
|
||||
if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && context.contextDependency == INDEPENDENT && !isStatement
|
||||
&& (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAnyOrNullableAny(expressionType))) {
|
||||
&& (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAnyOrNullableAny(expressionType))
|
||||
&& !TypesPackage.isDynamic(expressionType)) {
|
||||
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
|
||||
}
|
||||
return expressionType;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// !MARK_DYNAMIC_CALLS
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// MODULE[js]: m1
|
||||
// FILE: k.kt
|
||||
|
||||
fun <T> foo(t1: T, t2: T): T = t1
|
||||
|
||||
trait Tr
|
||||
class C: Tr
|
||||
fun <T: Tr> foo1(t1: T, t2: T): T = t1
|
||||
|
||||
fun test(d: dynamic, b: Boolean, n: String?) {
|
||||
foo(d, "").<!DEBUG_INFO_DYNAMIC!>foo<!>()
|
||||
foo1(d, C()).<!DEBUG_INFO_DYNAMIC!>foo<!>()
|
||||
|
||||
val fromIf = if (b) d else ""
|
||||
fromIf.<!DEBUG_INFO_DYNAMIC!>doo<!>()
|
||||
|
||||
val fromElvis = n ?: d
|
||||
fromElvis.<!DEBUG_INFO_DYNAMIC!>doo<!>()
|
||||
}
|
||||
|
||||
class In<in T>(t: T)
|
||||
fun <T> contra(a: In<T>, b: In<T>): T = null!!
|
||||
|
||||
fun testContra(d: dynamic) {
|
||||
contra(In(d), In("")).get(0) // not a dynamic call
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ T> contra(/*0*/ a: In<T>, /*1*/ b: In<T>): T
|
||||
internal fun </*0*/ T> foo(/*0*/ t1: T, /*1*/ t2: T): T
|
||||
internal fun </*0*/ T : Tr> foo1(/*0*/ t1: T, /*1*/ t2: T): T
|
||||
internal fun test(/*0*/ d: dynamic, /*1*/ b: kotlin.Boolean, /*2*/ n: kotlin.String?): kotlin.Unit
|
||||
internal fun testContra(/*0*/ d: dynamic): kotlin.Unit
|
||||
|
||||
internal final class C : Tr {
|
||||
public constructor C()
|
||||
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
|
||||
}
|
||||
|
||||
internal final class In</*0*/ in T> {
|
||||
public constructor In</*0*/ in T>(/*0*/ t: T)
|
||||
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
|
||||
}
|
||||
|
||||
internal trait Tr {
|
||||
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
|
||||
}
|
||||
@@ -3758,6 +3758,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inference.kt")
|
||||
public void testInference() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dynamicTypes/inference.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("membersOfAny.kt")
|
||||
public void testMembersOfAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dynamicTypes/membersOfAny.kt");
|
||||
|
||||
Reference in New Issue
Block a user