Prohibit use of captured type as argument for reified parameter

#KT-8093 Fixed
This commit is contained in:
Denis Zharkov
2016-01-19 11:03:39 +03:00
parent 751f66c656
commit 70dc5b5403
4 changed files with 28 additions and 1 deletions
@@ -0,0 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A<F>
inline fun <reified T> foo(x: A<T>) {}
fun test(x: A<out CharSequence>) {
<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo<!>(x)
}
@@ -0,0 +1,11 @@
package
public inline fun </*0*/ reified T> foo(/*0*/ x: A<T>): kotlin.Unit
public fun test(/*0*/ x: A<out kotlin.CharSequence>): kotlin.Unit
public final class A</*0*/ F> {
public constructor A</*0*/ F>()
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
}
@@ -7376,6 +7376,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/tpAsReified"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("CapturedAsReified.kt")
public void testCapturedAsReified() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt");
doTest(fileName);
}
@TestMetadata("Conventions.kt")
public void testConventions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.kt");
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import java.util.*
@@ -66,7 +67,8 @@ fun KotlinType?.isArrayOfNothing(): Boolean {
fun KotlinType.isSubtypeOf(superType: KotlinType): Boolean = KotlinTypeChecker.DEFAULT.isSubtypeOf(this, superType)
fun KotlinType.cannotBeReified(): Boolean = KotlinBuiltIns.isNothingOrNullableNothing(this) || this.isDynamic()
fun KotlinType.cannotBeReified(): Boolean =
KotlinBuiltIns.isNothingOrNullableNothing(this) || this.isDynamic() || this.isCaptured()
fun KotlinType.unsafeAsReifiedArgument(): Boolean = arguments.any { !it.isStarProjection }
fun TypeProjection.substitute(doSubstitute: (KotlinType) -> KotlinType): TypeProjection {