[FIR] Add PLATFORM_CLASS_MAPPED_TO_KOTLIN
This commit is contained in:
committed by
TeamCityServer
parent
51b73bb6ae
commit
f046f2964b
+7
@@ -1897,6 +1897,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) { firDiagnostic ->
|
||||
PlatformClassMappedToKotlinImpl(
|
||||
firDiagnostic.a,
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED) { firDiagnostic ->
|
||||
ExtensionInClassReferenceNotAllowedImpl(
|
||||
firSymbolBuilder.callableBuilder.buildCallableSymbol(firDiagnostic.a.fir),
|
||||
|
||||
+5
@@ -1352,6 +1352,11 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = RedundantNullable::class
|
||||
}
|
||||
|
||||
abstract class PlatformClassMappedToKotlin : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = PlatformClassMappedToKotlin::class
|
||||
abstract val kotlinClass: FqName
|
||||
}
|
||||
|
||||
abstract class ExtensionInClassReferenceNotAllowed : KtFirDiagnostic<KtExpression>() {
|
||||
override val diagnosticClass get() = ExtensionInClassReferenceNotAllowed::class
|
||||
abstract val referencedDeclaration: KtCallableSymbol
|
||||
|
||||
+6
@@ -1622,6 +1622,12 @@ internal class RedundantNullableImpl(
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.RedundantNullable(), KtAbstractFirDiagnostic<KtTypeReference>
|
||||
|
||||
internal class PlatformClassMappedToKotlinImpl(
|
||||
override val kotlinClass: FqName,
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.PlatformClassMappedToKotlin(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
internal class ExtensionInClassReferenceNotAllowedImpl(
|
||||
override val referencedDeclaration: KtCallableSymbol,
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
class A {
|
||||
<!VALUE_CLASS_NOT_TOP_LEVEL!>inline<!> inner class B(val x: Int)
|
||||
fun foo() {
|
||||
@@ -11,7 +12,7 @@ class A {
|
||||
<!VALUE_CLASS_NOT_FINAL!>sealed<!> inline class NotFinalClass3(val x: Int)
|
||||
|
||||
<!VALUE_CLASS_CANNOT_BE_CLONEABLE, VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION!>value<!> class CloneableClass1(val x: Int): Cloneable
|
||||
<!VALUE_CLASS_CANNOT_BE_CLONEABLE!>inline<!> class CloneableClass2(val x: Int): java.lang.Cloneable
|
||||
<!VALUE_CLASS_CANNOT_BE_CLONEABLE!>inline<!> class CloneableClass2(val x: Int): <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Cloneable<!>
|
||||
|
||||
open class Test
|
||||
inline class ExtendTest(val x: Int): <!SUPERTYPE_NOT_INITIALIZED, VALUE_CLASS_CANNOT_EXTEND_CLASSES!>Test<!>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import kotlin.jvm.functions.Function0
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
val x: Function0<Int> = <!INITIALIZER_TYPE_MISMATCH!>{ 42 }<!>
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>kotlin.jvm.functions.Function0<!>
|
||||
|
||||
val x: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN, PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Function0<Int><!> = <!INITIALIZER_TYPE_MISMATCH!>{ 42 }<!>
|
||||
|
||||
val y: Function1<String, String> = { it }
|
||||
|
||||
|
||||
Vendored
+2
-1
@@ -1,7 +1,8 @@
|
||||
// FULL_JDK
|
||||
// ISSUE: KT-48113
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
fun collapse(path: String) {
|
||||
val result = (path as java.lang.String).replace("123", "456")
|
||||
val result = (path as <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.String<!>).replace("123", "456")
|
||||
if (result !== path) {}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
// MODULE: m1
|
||||
// FILE: base.kt
|
||||
|
||||
@@ -5,7 +6,7 @@ package hello
|
||||
|
||||
class Hello(val msg: String)
|
||||
|
||||
class Test(val set: java.util.Set<*>)
|
||||
class Test(val set: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.Set<*><!>)
|
||||
|
||||
// MODULE: m2(m1)
|
||||
// FILE: user.kt
|
||||
|
||||
+4
@@ -657,6 +657,10 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
}
|
||||
|
||||
val REDUNDANT_NULLABLE by warning<KtTypeReference>(PositioningStrategy.REDUNDANT_NULLABLE)
|
||||
|
||||
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning<PsiElement>(PositioningStrategy.REFERENCED_NAME_BY_QUALIFIED) {
|
||||
parameter<FqName>("kotlinClass")
|
||||
}
|
||||
}
|
||||
|
||||
val REFLECTION by object : DiagnosticGroup("Reflection") {
|
||||
|
||||
@@ -396,6 +396,7 @@ object FirErrors {
|
||||
val TYPE_VARIANCE_CONFLICT_IN_EXPANDED_TYPE by error4<PsiElement, FirTypeParameterSymbol, Variance, Variance, ConeKotlinType>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val SMARTCAST_IMPOSSIBLE by error4<KtExpression, ConeKotlinType, FirExpression, String, Boolean>()
|
||||
val REDUNDANT_NULLABLE by warning0<KtTypeReference>(SourceElementPositioningStrategies.REDUNDANT_NULLABLE)
|
||||
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning1<PsiElement, FqName>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
||||
|
||||
// Reflection
|
||||
val EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED by error1<KtExpression, FirCallableSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
|
||||
+5
@@ -11,6 +11,11 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extended.*
|
||||
|
||||
object ExtendedDeclarationCheckers : DeclarationCheckers() {
|
||||
override val fileCheckers: Set<FirFileChecker>
|
||||
get() = setOf(
|
||||
PlatformClassMappedToKotlinImportsChecker
|
||||
)
|
||||
|
||||
override val basicDeclarationCheckers: Set<FirBasicDeclarationChecker>
|
||||
get() = setOf(
|
||||
RedundantVisibilityModifierSyntaxChecker,
|
||||
|
||||
+3
-1
@@ -5,11 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extended.PlatformClassMappedToKotlinTypeRefChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extended.RedundantNullableChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.*
|
||||
|
||||
object ExtendedTypeCheckers : TypeCheckers() {
|
||||
override val typeRefCheckers: Set<FirTypeRefChecker> = setOf(
|
||||
RedundantNullableChecker
|
||||
RedundantNullableChecker,
|
||||
PlatformClassMappedToKotlinTypeRefChecker
|
||||
)
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.extended
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirFileChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
import org.jetbrains.kotlin.fir.scopes.platformClassMapper
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
object PlatformClassMappedToKotlinImportsChecker : FirFileChecker() {
|
||||
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
declaration.imports.forEach { import ->
|
||||
val importedFqName = import.importedFqName ?: return
|
||||
if (importedFqName.isRoot || importedFqName.shortName().asString().isEmpty()) return
|
||||
val classId = (import as? FirResolvedImport)?.resolvedParentClassId ?: ClassId.topLevel(importedFqName)
|
||||
if (classId.asSingleFqName() != importedFqName) {
|
||||
return
|
||||
}
|
||||
|
||||
val kotlinClass = context.session.platformClassMapper.getCorrespondingKotlinClass(classId)
|
||||
if (kotlinClass != null) {
|
||||
reporter.reportOn(import.source, FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN, importedFqName, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.extended
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.FirTypeRefChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.scopes.platformClassMapper
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.classId
|
||||
|
||||
object PlatformClassMappedToKotlinTypeRefChecker : FirTypeRefChecker() {
|
||||
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (typeRef is FirResolvedTypeRef) {
|
||||
val kotlinClass = context.session.platformClassMapper.getCorrespondingKotlinClass(typeRef.type.classId)
|
||||
if (kotlinClass != null) {
|
||||
reporter.reportOn(typeRef.source, FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN, kotlinClass.asSingleFqName(), context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -349,6 +349,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.OVERRIDE_BY_INLIN
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.OVERRIDE_DEPRECATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.OVERRIDING_FINAL_MEMBER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PACKAGE_CANNOT_BE_IMPORTED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIVATE_CLASS_MEMBER_FROM_INLINE
|
||||
@@ -624,6 +625,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton")
|
||||
map.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable")
|
||||
map.put(REDUNDANT_NULLABLE, "Redundant '?'")
|
||||
map.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn't be used in Kotlin. Use {0} instead.", TO_STRING)
|
||||
map.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list")
|
||||
map.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice")
|
||||
map.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes")
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// FILE: a.kt
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
package foobar.a
|
||||
import java.*
|
||||
|
||||
val a : java.util.List<Int>? = null
|
||||
val a : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<Int><!>? = null
|
||||
val a2 : <!UNRESOLVED_REFERENCE!>util.List<Int><!>? = null
|
||||
val a3 : <!UNRESOLVED_REFERENCE!>LinkedList<Int><!>? = null
|
||||
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
// FILE: a.kt
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
package foobar.a
|
||||
import java.*
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
interface A<T> {}
|
||||
interface B<T> {}
|
||||
interface C<T> {}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
// Fixpoint generic in Java: Enum<T extends Enum<T>>
|
||||
fun test(a : java.lang.annotation.RetentionPolicy) {
|
||||
|
||||
}
|
||||
|
||||
fun test() {
|
||||
java.util.Collections.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>()
|
||||
val a : Collection<String>? = java.util.Collections.emptyList()
|
||||
}
|
||||
|
||||
fun test(a : java.lang.Comparable<Int>) {
|
||||
|
||||
}
|
||||
|
||||
fun test(a : java.util.ArrayList<Int>) {
|
||||
|
||||
}
|
||||
|
||||
fun test(a : java.lang.Class<Int>) {
|
||||
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
// Fixpoint generic in Java: Enum<T extends Enum<T>>
|
||||
fun test(a : java.lang.annotation.RetentionPolicy) {
|
||||
|
||||
|
||||
+11
-10
@@ -1,6 +1,7 @@
|
||||
// !CHECK_TYPE
|
||||
// SKIP_JAVAC
|
||||
// FULL_JDK
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
@@ -9,17 +10,17 @@ import java.util.*
|
||||
import utils.*
|
||||
|
||||
import java.io.PrintStream
|
||||
import java.lang.Comparable as Com
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Com
|
||||
|
||||
val l : MutableList<in Int> = ArrayList<Int>()
|
||||
|
||||
fun test(l : java.util.List<Int>) {
|
||||
val x : <!UNRESOLVED_REFERENCE!>java.List<!>
|
||||
val y : java.util.List<Int>
|
||||
val b : java.lang.Object
|
||||
val z : <!UNRESOLVED_REFERENCE!>java.utils.List<Int><!>
|
||||
fun test(l : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<Int><!>) {
|
||||
val <!UNUSED_VARIABLE!>x<!> : <!UNRESOLVED_REFERENCE!>java.List<!>
|
||||
val <!UNUSED_VARIABLE!>y<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<Int><!>
|
||||
val <!UNUSED_VARIABLE!>b<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Object<!>
|
||||
val <!UNUSED_VARIABLE!>z<!> : <!UNRESOLVED_REFERENCE!>java.utils.List<Int><!>
|
||||
|
||||
val f : java.io.File? = null
|
||||
val <!UNUSED_VARIABLE!>f<!> : java.io.File? = null
|
||||
|
||||
Collections.<!FUNCTION_CALL_EXPECTED!>emptyList<!>
|
||||
Collections.<!FUNCTION_CALL_EXPECTED!>emptyList<!><<!CANNOT_INFER_PARAMETER_TYPE!>Int<!>>
|
||||
@@ -32,7 +33,7 @@ fun test(l : java.util.List<Int>) {
|
||||
<!NO_COMPANION_OBJECT!>List<Int><!>
|
||||
|
||||
|
||||
val o = "sdf" as Object
|
||||
val <!UNUSED_VARIABLE!>o<!> = "sdf" as <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!>
|
||||
|
||||
try {
|
||||
// ...
|
||||
@@ -43,9 +44,9 @@ fun test(l : java.util.List<Int>) {
|
||||
|
||||
PrintStream("sdf")
|
||||
|
||||
val c : Com<Int>? = null
|
||||
val c : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Com<Int><!>? = null
|
||||
|
||||
checkSubtype<java.lang.Comparable<Int>?>(c)
|
||||
checkSubtype<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<Int><!>?>(c)
|
||||
|
||||
// Collections.sort<Integer>(ArrayList<Integer>())
|
||||
xxx.<!UNRESOLVED_REFERENCE!>Class<!>()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// !CHECK_TYPE
|
||||
// SKIP_JAVAC
|
||||
// FULL_JDK
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
interface MyTrait: <!INTERFACE_WITH_SUPERCLASS!>Object<!> {
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
interface MyTrait: <!INTERFACE_WITH_SUPERCLASS, PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!> {
|
||||
override fun toString(): String
|
||||
public override fun finalize()
|
||||
public <!OVERRIDING_FINAL_MEMBER!>override<!> fun wait()
|
||||
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> <!OVERRIDING_FINAL_MEMBER!>override<!> fun wait()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
interface MyTrait: <!INTERFACE_WITH_SUPERCLASS, PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!> {
|
||||
override fun toString(): String
|
||||
public override fun finalize()
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
class TestIface(r : Runnable) : Runnable by r {}
|
||||
|
||||
class TestObject(o : Object) : <!DELEGATION_NOT_TO_INTERFACE, SUPERTYPE_NOT_INITIALIZED!>Object<!> by o {}
|
||||
class TestObject(o : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!>) : <!DELEGATION_NOT_TO_INTERFACE, PLATFORM_CLASS_MAPPED_TO_KOTLIN, PLATFORM_CLASS_MAPPED_TO_KOTLIN, PLATFORM_CLASS_MAPPED_TO_KOTLIN, SUPERTYPE_NOT_INITIALIZED!>Object<!> by o {}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
class TestIface(r : Runnable) : Runnable by r {}
|
||||
|
||||
class TestObject(o : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!>) : <!DELEGATION_NOT_TO_INTERFACE, PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!> by o {}
|
||||
@@ -1,6 +0,0 @@
|
||||
import java.lang.reflect.*
|
||||
import java.util.List
|
||||
|
||||
fun foo(
|
||||
p1: Array<String> /* should be resolved to kotlin.Array */,
|
||||
p2: List<String> /* should be resolved to java.util.List */) { }
|
||||
@@ -1,3 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
import java.lang.reflect.*
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<!>
|
||||
|
||||
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
package i
|
||||
|
||||
@@ -7,7 +8,7 @@ import java.util.*
|
||||
import checkSubtype
|
||||
|
||||
fun <T, R> Collection<T>.map1(f : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun <T, R> java.lang.Iterable<T>.map1(f : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun <T, R> <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<T><!>.map1(f : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun test(list: List<Int>) {
|
||||
val res = list.map1 { it }
|
||||
@@ -16,7 +17,7 @@ fun test(list: List<Int>) {
|
||||
}
|
||||
|
||||
fun <T> Collection<T>.foo() {}
|
||||
fun <T> java.lang.Iterable<T>.foo() {}
|
||||
fun <T> <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<T><!>.foo() {}
|
||||
|
||||
fun test1(list: List<Int>) {
|
||||
val res = list.foo()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
package i
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
//KT-2606 Filter java.util.* import
|
||||
package n
|
||||
|
||||
import java.util.*
|
||||
import java.lang.annotation.*
|
||||
|
||||
fun bar() : Iterator<Int>? {
|
||||
val i : Iterable<Integer>
|
||||
val a : Annotation
|
||||
return null
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
//KT-2606 Filter java.util.* import
|
||||
package n
|
||||
|
||||
|
||||
+10
-9
@@ -1,20 +1,21 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
package a
|
||||
|
||||
import java.util.Iterator
|
||||
import java.lang.Comparable as Comp
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.Iterator<!>
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Comp
|
||||
|
||||
import checkSubtype
|
||||
|
||||
fun bar(any: Any): java.lang.Iterable<Int>? {
|
||||
val a: java.lang.Comparable<String>? = null
|
||||
val b: Iterable<Integer>
|
||||
val c : Iterator<String>? = null
|
||||
fun bar(any: Any): <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<Int><!>? {
|
||||
val <!UNUSED_VARIABLE!>a<!>: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<String><!>? = null
|
||||
val <!UNUSED_VARIABLE!>b<!>: Iterable<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Integer<!>>
|
||||
val <!UNUSED_VARIABLE!>c<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<String><!>? = null
|
||||
|
||||
if (any is Iterator<*>) {
|
||||
checkSubtype<Iterator<*>>(any)
|
||||
if (any is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>) {
|
||||
checkSubtype<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>>(any)
|
||||
}
|
||||
any as Iterator<*>
|
||||
any as <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
//KT-1778 Automatically cast error
|
||||
package kt1778
|
||||
|
||||
@@ -6,7 +7,7 @@ import checkSubtype
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val x = checkSubtype<Any>(args[0])
|
||||
if(x is java.lang.CharSequence) {
|
||||
if(x is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.CharSequence<!>) {
|
||||
if (<!EQUALITY_NOT_APPLICABLE!>"a" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // OK
|
||||
if (<!EQUALITY_NOT_APPLICABLE!>"a" == x<!> || <!EQUALITY_NOT_APPLICABLE!>"b" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // <– THEN ERROR
|
||||
if (<!EQUALITY_NOT_APPLICABLE!>"a" == x<!> && <!EQUALITY_NOT_APPLICABLE!>"a" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // <– ELSE ERROR
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
//KT-1778 Automatically cast error
|
||||
package kt1778
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
class Generic<T>
|
||||
|
||||
fun redundantNullable(
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
interface A
|
||||
interface X: A<!NULLABLE_SUPERTYPE!>?<!><!REDUNDANT_NULLABLE!>?<!> {
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// JET-72 Type inference doesn't work when iterating over ArrayList
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
abstract class Item(val room: Object) {
|
||||
abstract val name : String
|
||||
}
|
||||
|
||||
val items: ArrayList<Item> = ArrayList<Item>()
|
||||
|
||||
fun test(room : Object) {
|
||||
for(item: Item? in items) {
|
||||
if (item?.room === room) {
|
||||
// item?.room is not null
|
||||
System.out.println("You see " + <!SAFE_CALL_WILL_CHANGE_NULLABILITY!>item<!UNNECESSARY_SAFE_CALL!>?.<!>name<!>)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
// JET-72 Type inference doesn't work when iterating over ArrayList
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
import java.lang.Comparable as Comparable
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Comparable
|
||||
|
||||
fun f(c: Comparable<*>) {
|
||||
fun f(c: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Comparable<*><!>) {
|
||||
checkSubtype<kotlin.Comparable<*>>(<!ARGUMENT_TYPE_MISMATCH!>c<!>)
|
||||
checkSubtype<java.lang.Comparable<*>>(c)
|
||||
}
|
||||
checkSubtype<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<*><!>>(c)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Comparable
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// KT-498 Very strange error in the type checker
|
||||
|
||||
class IdUnavailableException() : Exception() {}
|
||||
|
||||
fun <T : Any> T.getJavaClass() : Class<T> {
|
||||
return ((this as Object).getClass()) <!UNCHECKED_CAST!>as Class<T><!> // Some error here, because of Exception() used above. ?!!!
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// KT-498 Very strange error in the type checker
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// KT-716 Type inference failed
|
||||
|
||||
class TypeInfo<T>
|
||||
|
||||
fun <T> typeinfo() : TypeInfo<T> = null <!CAST_NEVER_SUCCEEDS!>as<!> TypeInfo<T>
|
||||
|
||||
fun <T> TypeInfo<T>.getJavaClass() : java.lang.Class<T> {
|
||||
val t : java.lang.Object = this as java.lang.Object
|
||||
return t.getClass() <!UNCHECKED_CAST!>as java.lang.Class<T><!> // inferred type is Object but Serializable was expected
|
||||
}
|
||||
|
||||
fun <T> getJavaClass() = typeinfo<T>().getJavaClass()
|
||||
|
||||
fun main() {
|
||||
System.out.println(getJavaClass<String>())
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
// KT-716 Type inference failed
|
||||
|
||||
class TypeInfo<T>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(p: java.util.List<String>) {
|
||||
p.iterator(); // forcing resolve of java.util.List.iterator()
|
||||
|
||||
ArrayList<String>().iterator(); // this provoked exception in SignaturesPropagationData
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(p: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<String><!>) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
//FILE:a.kt
|
||||
package a
|
||||
|
||||
@@ -44,6 +46,6 @@ class Q {
|
||||
}
|
||||
|
||||
//check that 'toString' can be invoked without specifying return type
|
||||
class NewClass : java.util.ArrayList<Integer>() {
|
||||
public override fun toString() = "a"
|
||||
class NewClass : java.util.ArrayList<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Integer<!>>() {
|
||||
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> override fun toString() = "a"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// WITH_EXTENDED_CHECKERS
|
||||
|
||||
//FILE:a.kt
|
||||
package a
|
||||
|
||||
|
||||
Reference in New Issue
Block a user