[K2] Disappeared UNSUPPORTED
Prohibit Array<Nothing> ^KT-59881
This commit is contained in:
committed by
Space Team
parent
73a0b4eaf2
commit
85cff98a38
+1
@@ -57,6 +57,7 @@ object CommonExpressionCheckers : ExpressionCheckers() {
|
||||
FirIncompatibleClassExpressionChecker,
|
||||
FirMissingDependencyClassChecker,
|
||||
FirMissingDependencySupertypeChecker.ForQualifiedAccessExpressions,
|
||||
FirArrayOfNothingQualifierChecker,
|
||||
)
|
||||
|
||||
override val callCheckers: Set<FirCallChecker>
|
||||
|
||||
+1
@@ -22,5 +22,6 @@ object CommonTypeCheckers : TypeCheckers() {
|
||||
FirOptionalExpectationTypeChecker,
|
||||
FirIncompatibleClassTypeChecker,
|
||||
FirContextReceiversTypeChecker,
|
||||
FirArrayOfNothingTypeChecker,
|
||||
)
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.expression
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
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.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
object FirArrayOfNothingQualifierChecker : FirQualifiedAccessExpressionChecker() {
|
||||
override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val resolvedType = expression.resolvedType
|
||||
checkTypeAndTypeArguments(resolvedType, expression.calleeReference.source, context, reporter)
|
||||
}
|
||||
|
||||
fun ConeKotlinType.isArrayOfNothing(): Boolean {
|
||||
if (!this.isArrayTypeOrNullableArrayType) return false
|
||||
val typeParameterType = type.typeArguments.firstOrNull()?.type ?: return false
|
||||
return typeParameterType.isNothingOrNullableNothing
|
||||
}
|
||||
|
||||
private fun checkTypeAndTypeArguments(
|
||||
type: ConeKotlinType,
|
||||
source: KtSourceElement?,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter,
|
||||
) {
|
||||
if (type.isArrayOfNothing()) {
|
||||
reporter.reportOn(source, FirErrors.UNSUPPORTED, "Array<Nothing> is illegal", context)
|
||||
} else {
|
||||
for (typeArg in type.typeArguments) {
|
||||
val typeArgType = typeArg.type ?: continue
|
||||
checkTypeAndTypeArguments(typeArgType, source, context, reporter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.type
|
||||
|
||||
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.expression.FirArrayOfNothingQualifierChecker.isArrayOfNothing
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.TYPEALIAS_EXPANDS_TO_ARRAY_OF_NOTHINGS
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeAlias
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
object FirArrayOfNothingTypeChecker : FirTypeRefChecker() {
|
||||
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
/** Ignore typealias, see [TYPEALIAS_EXPANDS_TO_ARRAY_OF_NOTHINGS] */
|
||||
if (context.containingDeclarations.lastOrNull() is FirTypeAlias) return
|
||||
val coneType = typeRef.coneTypeOrNull ?: return
|
||||
val fullyExpandedType = coneType.fullyExpandedType(context.session)
|
||||
|
||||
/** Ignore vararg, see varargOfNothing.kt test */
|
||||
val isVararg = (context.containingDeclarations.lastOrNull() as? FirValueParameter)?.isVararg ?: false
|
||||
if (!isVararg && fullyExpandedType.isArrayOfNothing()) {
|
||||
reporter.reportOn(typeRef.source, FirErrors.UNSUPPORTED, "Array<Nothing> is illegal", context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,12 +43,9 @@ val ConeKotlinType.isPrimitiveOrNullablePrimitive: Boolean get() = isAnyOfBuilti
|
||||
val ConeKotlinType.isPrimitive: Boolean get() = isPrimitiveOrNullablePrimitive && nullability == ConeNullability.NOT_NULL
|
||||
val ConeKotlinType.isPrimitiveNumberOrNullableType: Boolean
|
||||
get() = isPrimitiveOrNullablePrimitive && !isBooleanOrNullableBoolean && !isCharOrNullableChar
|
||||
val ConeKotlinType.isArrayType: Boolean
|
||||
get() {
|
||||
return isBuiltinType(StandardClassIds.Array, false) ||
|
||||
StandardClassIds.primitiveArrayTypeByElementType.values.any { isBuiltinType(it, false) } ||
|
||||
StandardClassIds.unsignedArrayTypeByElementType.values.any { isBuiltinType(it, false) }
|
||||
}
|
||||
|
||||
val ConeKotlinType.isArrayType: Boolean get() = isArrayType(isNullable = false)
|
||||
val ConeKotlinType.isArrayTypeOrNullableArrayType: Boolean get() = isArrayType(isNullable = null)
|
||||
|
||||
// Same as [KotlinBuiltIns#isNonPrimitiveArray]
|
||||
val ConeKotlinType.isNonPrimitiveArray: Boolean
|
||||
@@ -75,3 +72,9 @@ private fun ConeKotlinType.isAnyOfBuiltinType(classIds: Set<ClassId>): Boolean {
|
||||
if (this !is ConeClassLikeType) return false
|
||||
return lookupTag.classId in classIds
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.isArrayType(isNullable: Boolean?): Boolean {
|
||||
return isBuiltinType(StandardClassIds.Array, isNullable) ||
|
||||
StandardClassIds.primitiveArrayTypeByElementType.values.any { isBuiltinType(it, isNullable) } ||
|
||||
StandardClassIds.unsignedArrayTypeByElementType.values.any { isBuiltinType(it, isNullable) }
|
||||
}
|
||||
@@ -1,32 +1,38 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST -USELESS_CAST
|
||||
// !LANGUAGE: +ProhibitNonReifiedArraysAsReifiedTypeArguments
|
||||
class A<T>
|
||||
class C<T, G>
|
||||
class D<T>
|
||||
|
||||
fun test1(
|
||||
a: Array<Nothing>,
|
||||
b: Array<Nothing?>,
|
||||
c: Array<in Nothing>,
|
||||
d: Array<in Nothing?>,
|
||||
e: Array<out Nothing>,
|
||||
f: Array<out Nothing?>
|
||||
) {}
|
||||
a: <!UNSUPPORTED!>Array<Nothing><!>,
|
||||
b: <!UNSUPPORTED!>Array<Nothing?><!>,
|
||||
c: <!UNSUPPORTED!>Array<in Nothing><!>,
|
||||
d: <!UNSUPPORTED!>Array<in Nothing?><!>,
|
||||
e: <!UNSUPPORTED!>Array<out Nothing><!>,
|
||||
f: <!UNSUPPORTED!>Array<out Nothing?><!>,
|
||||
g: C<String, <!UNSUPPORTED!>Array<Nothing><!>>,
|
||||
h: A<D<<!UNSUPPORTED!>Array<Nothing><!>>>
|
||||
) {
|
||||
<!UNSUPPORTED!>A<!><D<<!UNSUPPORTED!>Array<Nothing><!>>>()
|
||||
}
|
||||
|
||||
fun test2(
|
||||
a: Array<Nothing>?,
|
||||
b: Array<Nothing?>?,
|
||||
c: Array<in Nothing>?,
|
||||
d: Array<in Nothing?>?,
|
||||
e: Array<out Nothing>?,
|
||||
f: Array<out Nothing?>?
|
||||
a: <!UNSUPPORTED!>Array<Nothing>?<!>,
|
||||
b: <!UNSUPPORTED!>Array<Nothing?>?<!>,
|
||||
c: <!UNSUPPORTED!>Array<in Nothing>?<!>,
|
||||
d: <!UNSUPPORTED!>Array<in Nothing?>?<!>,
|
||||
e: <!UNSUPPORTED!>Array<out Nothing>?<!>,
|
||||
f: <!UNSUPPORTED!>Array<out Nothing?>?<!>
|
||||
) {}
|
||||
|
||||
fun test3(
|
||||
a: A<Array<Nothing>>,
|
||||
b: A<Array<Nothing?>>,
|
||||
c: A<Array<in Nothing>>,
|
||||
d: A<Array<in Nothing?>>,
|
||||
e: A<Array<out Nothing>>,
|
||||
f: A<Array<out Nothing?>>
|
||||
a: A<<!UNSUPPORTED!>Array<Nothing><!>>,
|
||||
b: A<<!UNSUPPORTED!>Array<Nothing?><!>>,
|
||||
c: A<<!UNSUPPORTED!>Array<in Nothing><!>>,
|
||||
d: A<<!UNSUPPORTED!>Array<in Nothing?><!>>,
|
||||
e: A<<!UNSUPPORTED!>Array<out Nothing><!>>,
|
||||
f: A<<!UNSUPPORTED!>Array<out Nothing?><!>>
|
||||
) {}
|
||||
|
||||
fun test4(
|
||||
@@ -39,17 +45,16 @@ fun test4(
|
||||
) {}
|
||||
|
||||
fun test5() {
|
||||
arrayOf<<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing<!>>()
|
||||
Array<<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing<!>>(10) { throw Exception() }
|
||||
<!UNSUPPORTED!>arrayOf<!><<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing<!>>()
|
||||
<!UNSUPPORTED!>Array<!><<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing<!>>(10) { throw Exception() }
|
||||
}
|
||||
|
||||
fun <T> foo(): Array<T> = (object {} as Any) as Array<T>
|
||||
|
||||
fun test6() = foo<Nothing>()
|
||||
|
||||
fun test6() = <!UNSUPPORTED!>foo<!><Nothing>()
|
||||
|
||||
class B<T>(val array: Array<T>)
|
||||
|
||||
fun <T> bar() = B<Array<T>>(<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>arrayOf<!>())
|
||||
|
||||
fun test7() = bar<Nothing>()
|
||||
fun test7() = <!UNSUPPORTED!>bar<!><Nothing>()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST -USELESS_CAST
|
||||
// !LANGUAGE: +ProhibitNonReifiedArraysAsReifiedTypeArguments
|
||||
class A<T>
|
||||
class C<T, G>
|
||||
class D<T>
|
||||
|
||||
fun test1(
|
||||
a: <!UNSUPPORTED!>Array<Nothing><!>,
|
||||
@@ -8,8 +10,12 @@ fun test1(
|
||||
c: <!UNSUPPORTED!>Array<in Nothing><!>,
|
||||
d: <!UNSUPPORTED!>Array<in Nothing?><!>,
|
||||
e: <!UNSUPPORTED!>Array<out Nothing><!>,
|
||||
f: <!UNSUPPORTED!>Array<out Nothing?><!>
|
||||
) {}
|
||||
f: <!UNSUPPORTED!>Array<out Nothing?><!>,
|
||||
g: C<String, <!UNSUPPORTED!>Array<Nothing><!>>,
|
||||
h: A<D<<!UNSUPPORTED!>Array<Nothing><!>>>
|
||||
) {
|
||||
<!UNSUPPORTED!>A<!><D<<!UNSUPPORTED!>Array<Nothing><!>>>()
|
||||
}
|
||||
|
||||
fun test2(
|
||||
a: <!UNSUPPORTED!>Array<Nothing><!>?,
|
||||
@@ -47,7 +53,6 @@ fun <T> foo(): Array<T> = (object {} as Any) as Array<T>
|
||||
|
||||
fun test6() = <!UNSUPPORTED!>foo<!><Nothing>()
|
||||
|
||||
|
||||
class B<T>(val array: Array<T>)
|
||||
|
||||
fun <T> bar() = B<Array<T>>(<!TYPE_PARAMETER_AS_REIFIED_ARRAY_ERROR!>arrayOf<!>())
|
||||
|
||||
@@ -2,7 +2,7 @@ package
|
||||
|
||||
public fun </*0*/ T> bar(): B<kotlin.Array<T>>
|
||||
public fun </*0*/ T> foo(): kotlin.Array<T>
|
||||
public fun test1(/*0*/ a: kotlin.Array<kotlin.Nothing>, /*1*/ b: kotlin.Array<kotlin.Nothing?>, /*2*/ c: kotlin.Array<in kotlin.Nothing>, /*3*/ d: kotlin.Array<in kotlin.Nothing?>, /*4*/ e: kotlin.Array<out kotlin.Nothing>, /*5*/ f: kotlin.Array<out kotlin.Nothing?>): kotlin.Unit
|
||||
public fun test1(/*0*/ a: kotlin.Array<kotlin.Nothing>, /*1*/ b: kotlin.Array<kotlin.Nothing?>, /*2*/ c: kotlin.Array<in kotlin.Nothing>, /*3*/ d: kotlin.Array<in kotlin.Nothing?>, /*4*/ e: kotlin.Array<out kotlin.Nothing>, /*5*/ f: kotlin.Array<out kotlin.Nothing?>, /*6*/ g: C<kotlin.String, kotlin.Array<kotlin.Nothing>>, /*7*/ h: A<D<kotlin.Array<kotlin.Nothing>>>): kotlin.Unit
|
||||
public fun test2(/*0*/ a: kotlin.Array<kotlin.Nothing>?, /*1*/ b: kotlin.Array<kotlin.Nothing?>?, /*2*/ c: kotlin.Array<in kotlin.Nothing>?, /*3*/ d: kotlin.Array<in kotlin.Nothing?>?, /*4*/ e: kotlin.Array<out kotlin.Nothing>?, /*5*/ f: kotlin.Array<out kotlin.Nothing?>?): kotlin.Unit
|
||||
public fun test3(/*0*/ a: A<kotlin.Array<kotlin.Nothing>>, /*1*/ b: A<kotlin.Array<kotlin.Nothing?>>, /*2*/ c: A<kotlin.Array<in kotlin.Nothing>>, /*3*/ d: A<kotlin.Array<in kotlin.Nothing?>>, /*4*/ e: A<kotlin.Array<out kotlin.Nothing>>, /*5*/ f: A<kotlin.Array<out kotlin.Nothing?>>): kotlin.Unit
|
||||
public fun test4(/*0*/ a: kotlin.Array<A<kotlin.Nothing>>, /*1*/ b: kotlin.Array<A<kotlin.Nothing?>>, /*2*/ c: kotlin.Array<A<in kotlin.Nothing>>, /*3*/ d: kotlin.Array<A<in kotlin.Nothing?>>, /*4*/ e: kotlin.Array<A<out kotlin.Nothing>>, /*5*/ f: kotlin.Array<A<out kotlin.Nothing?>>): kotlin.Unit
|
||||
@@ -24,3 +24,18 @@ public final class B</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class C</*0*/ T, /*1*/ G> {
|
||||
public constructor C</*0*/ T, /*1*/ G>()
|
||||
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
|
||||
}
|
||||
|
||||
public final class D</*0*/ T> {
|
||||
public constructor D</*0*/ 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
|
||||
}
|
||||
|
||||
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -DEPRECATION
|
||||
|
||||
inline fun<reified T> foo(block: () -> T): String = block().toString()
|
||||
|
||||
inline fun <reified T: Any> javaClass(): Class<T> = T::class.java
|
||||
|
||||
fun box() {
|
||||
val a = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>arrayOf<!>(null!!)
|
||||
val b = Array<<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing?<!>>(5) { null!! }
|
||||
val c = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo<!>() { null!! }
|
||||
val d = foo<Any> { null!! }
|
||||
val e = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo<!> { "1" <!CAST_NEVER_SUCCEEDS!>as<!> Nothing }
|
||||
val e1 = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo<!> { "1" <!CAST_NEVER_SUCCEEDS!>as<!> Nothing? }
|
||||
|
||||
val f = javaClass<<!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>Nothing<!>>()
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -DEPRECATION
|
||||
|
||||
inline fun<reified T> foo(block: () -> T): String = block().toString()
|
||||
|
||||
Reference in New Issue
Block a user