diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index a5fc3411705..f736ba2e4d2 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrTypeArgument import org.jetbrains.kotlin.ir.types.IrTypeProjection +import org.jetbrains.kotlin.ir.types.impl.IrDefinitelyNotNullTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection @@ -188,7 +189,7 @@ class Fir2IrTypeConverter( } } is ConeDefinitelyNotNullType -> { - original.toIrType(typeContext.definitelyNotNull()) + IrDefinitelyNotNullTypeImpl(null, original.toIrType(typeContext)) } is ConeIntersectionType -> { // TODO: add intersectionTypeApproximation diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index c45f85112da..0c9e0d8c796 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.* import org.jetbrains.kotlin.fir.types.impl.* import org.jetbrains.kotlin.lexer.KtModifierKeywordToken +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.name.* import org.jetbrains.kotlin.utils.addToStdlib.runIf @@ -1937,11 +1938,7 @@ class DeclarationsConverter( source = typeRefSource isMarkedNullable = false } - INTERSECTION_TYPE -> firType = - buildErrorTypeRef { - source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) - } + INTERSECTION_TYPE -> firType = convertIntersectionType(typeRefSource, it, false) CONTEXT_RECEIVER_LIST, TokenType.ERROR_ELEMENT -> firType = buildErrorTypeRef { source = typeRefSource @@ -1963,6 +1960,29 @@ class DeclarationsConverter( private fun Collection.hasSuspend() = any { it.hasSuspend() } + private fun convertIntersectionType(typeRefSource: KtSourceElement, intersectionType: LighterASTNode, isNullable: Boolean): FirTypeRef { + val children = arrayListOf() + intersectionType.forEachChildren { + if (it.tokenType != KtTokens.AND) { //skip in forEachChildren? + children.add(convertType(it)) + } + } + + if (children.size != 2) { + return buildErrorTypeRef { + source = typeRefSource + diagnostic = ConeSimpleDiagnostic("Wrong code", DiagnosticKind.Syntax) + } + } + + return buildIntersectionTypeRef { + source = typeRefSource + isMarkedNullable = isNullable + leftType = children[0] + rightType = children[1] + } + } + /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeRefContents */ @@ -1997,11 +2017,7 @@ class DeclarationsConverter( source = typeRefSource isMarkedNullable = true } - INTERSECTION_TYPE -> firType = - buildErrorTypeRef { - source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) - } + INTERSECTION_TYPE -> firType = convertIntersectionType(typeRefSource, it, isNullable) } } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 8353b63060a..78e64feec60 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1751,9 +1751,11 @@ open class RawFirBuilder( } } } - is KtIntersectionType -> FirErrorTypeRefBuilder().apply { + is KtIntersectionType -> FirIntersectionTypeRefBuilder().apply { this.source = source - diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) + isMarkedNullable = isNullable + leftType = unwrappedElement.getLeftTypeRef()?.toFirOrErrorType() + rightType = unwrappedElement.getRightTypeRef()?.toFirOrErrorType() } null -> FirErrorTypeRefBuilder().apply { this.source = source diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index 611cf2ac509..3ccde0084d5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -485,6 +485,33 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { } is FirFunctionTypeRef -> createFunctionalType(typeRef) to null is FirDynamicTypeRef -> ConeKotlinErrorType(ConeUnsupportedDynamicType()) to null + is FirIntersectionTypeRef -> { + val (leftType, leftDiagnostic) = resolveType( + typeRef.leftType + ?: return ConeKotlinErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null, + scopeClassDeclaration, + areBareTypesAllowed, + isOperandOfIsOperator, + useSiteFile, + supertypeSupplier + ) + val (rightType, _) = resolveType( + typeRef.rightType + ?: return ConeKotlinErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null, + scopeClassDeclaration, + areBareTypesAllowed, + isOperandOfIsOperator, + useSiteFile, + supertypeSupplier + ) + + if (rightType.isAny && leftType is ConeTypeParameterType) { + ConeDefinitelyNotNullType(leftType) to leftDiagnostic //how properly concat (leftDiagnostic + rightDiagnostic)? + } else { + ConeKotlinErrorType(ConeUnsupported("Intersection types are not supported yet", typeRef.source)) to null + } + + } else -> error(typeRef.render()) } } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/FirIntersectionTypeRef.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/FirIntersectionTypeRef.kt new file mode 100644 index 00000000000..eb2da0f142a --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/FirIntersectionTypeRef.kt @@ -0,0 +1,32 @@ +/* + * 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.types + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +abstract class FirIntersectionTypeRef : FirTypeRefWithNullability() { + abstract override val source: KtSourceElement? + abstract override val annotations: List + abstract override val isMarkedNullable: Boolean + abstract val leftType: FirTypeRef? + abstract val rightType: FirTypeRef? + + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitIntersectionTypeRef(this, data) + + @Suppress("UNCHECKED_CAST") + override fun transform(transformer: FirTransformer, data: D): E = + transformer.transformIntersectionTypeRef(this, data) as E + + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirIntersectionTypeRef +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/builder/FirIntersectionTypeRefBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/builder/FirIntersectionTypeRefBuilder.kt new file mode 100644 index 00000000000..331b8806732 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/builder/FirIntersectionTypeRefBuilder.kt @@ -0,0 +1,49 @@ +/* + * 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.types.builder + +import kotlin.contracts.* +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder +import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.FirIntersectionTypeRefImpl +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +@FirBuilderDsl +class FirIntersectionTypeRefBuilder : FirAnnotationContainerBuilder { + override var source: KtSourceElement? = null + override val annotations: MutableList = mutableListOf() + var isMarkedNullable: Boolean by kotlin.properties.Delegates.notNull() + var leftType: FirTypeRef? = null + var rightType: FirTypeRef? = null + + override fun build(): FirIntersectionTypeRef { + return FirIntersectionTypeRefImpl( + source, + annotations, + isMarkedNullable, + leftType, + rightType, + ) + } + +} + +@OptIn(ExperimentalContracts::class) +inline fun buildIntersectionTypeRef(init: FirIntersectionTypeRefBuilder.() -> Unit): FirIntersectionTypeRef { + contract { + callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE) + } + return FirIntersectionTypeRefBuilder().apply(init).build() +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/impl/FirIntersectionTypeRefImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/impl/FirIntersectionTypeRefImpl.kt new file mode 100644 index 00000000000..a727533ad19 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/types/impl/FirIntersectionTypeRefImpl.kt @@ -0,0 +1,43 @@ +/* + * 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.types.impl + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +internal class FirIntersectionTypeRefImpl( + override val source: KtSourceElement?, + override val annotations: MutableList, + override val isMarkedNullable: Boolean, + override var leftType: FirTypeRef?, + override var rightType: FirTypeRef?, +) : FirIntersectionTypeRef() { + override fun acceptChildren(visitor: FirVisitor, data: D) { + annotations.forEach { it.accept(visitor, data) } + leftType?.accept(visitor, data) + rightType?.accept(visitor, data) + } + + override fun transformChildren(transformer: FirTransformer, data: D): FirIntersectionTypeRefImpl { + transformAnnotations(transformer, data) + leftType = leftType?.transform(transformer, data) + rightType = rightType?.transform(transformer, data) + return this + } + + override fun transformAnnotations(transformer: FirTransformer, data: D): FirIntersectionTypeRefImpl { + annotations.transformInplace(transformer, data) + return this + } +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt index fbdd78c092f..0909ddc3b01 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt @@ -135,6 +135,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRefWithNullability import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -278,6 +279,8 @@ abstract class FirDefaultVisitor : FirVisitor() { override fun visitFunctionTypeRef(functionTypeRef: FirFunctionTypeRef, data: D): R = visitTypeRefWithNullability(functionTypeRef, data) + override fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: D): R = visitTypeRefWithNullability(intersectionTypeRef, data) + override fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: D): R = visitTypeRef(implicitTypeRef, data) override fun visitLegacyRawContractDescription(legacyRawContractDescription: FirLegacyRawContractDescription, data: D): R = visitContractDescription(legacyRawContractDescription, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt index fb8efa36dac..5d3a8298bec 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt @@ -135,6 +135,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRefWithNullability import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -278,6 +279,8 @@ abstract class FirDefaultVisitorVoid : FirVisitorVoid() { override fun visitFunctionTypeRef(functionTypeRef: FirFunctionTypeRef) = visitTypeRefWithNullability(functionTypeRef) + override fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef) = visitTypeRefWithNullability(intersectionTypeRef) + override fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef) = visitTypeRef(implicitTypeRef) override fun visitLegacyRawContractDescription(legacyRawContractDescription: FirLegacyRawContractDescription) = visitContractDescription(legacyRawContractDescription) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt index 3ff6dac543d..5def54f3dde 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt @@ -135,6 +135,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRefWithNullability import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -667,6 +668,10 @@ abstract class FirTransformer : FirVisitor() { return transformElement(functionTypeRef, data) } + open fun transformIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: D): FirTypeRef { + return transformElement(intersectionTypeRef, data) + } + open fun transformImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: D): FirTypeRef { return transformElement(implicitTypeRef, data) } @@ -1211,6 +1216,10 @@ abstract class FirTransformer : FirVisitor() { return transformFunctionTypeRef(functionTypeRef, data) } + final override fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: D): FirTypeRef { + return transformIntersectionTypeRef(intersectionTypeRef, data) + } + final override fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: D): FirTypeRef { return transformImplicitTypeRef(implicitTypeRef, data) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt index 38d206b1aa5..cd288e675dd 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt @@ -135,6 +135,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRefWithNullability import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -408,6 +409,8 @@ abstract class FirVisitor { open fun visitFunctionTypeRef(functionTypeRef: FirFunctionTypeRef, data: D): R = visitElement(functionTypeRef, data) + open fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: D): R = visitElement(intersectionTypeRef, data) + open fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: D): R = visitElement(implicitTypeRef, data) open fun visitEffectDeclaration(effectDeclaration: FirEffectDeclaration, data: D): R = visitElement(effectDeclaration, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt index 521641c029c..fb99d944cfe 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt @@ -135,6 +135,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRefWithNullability import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef +import org.jetbrains.kotlin.fir.types.FirIntersectionTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -666,6 +667,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitElement(functionTypeRef) } + open fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef) { + visitElement(intersectionTypeRef) + } + open fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef) { visitElement(implicitTypeRef) } @@ -1210,6 +1215,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitFunctionTypeRef(functionTypeRef) } + final override fun visitIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: Nothing?) { + visitIntersectionTypeRef(intersectionTypeRef) + } + final override fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: Nothing?) { visitImplicitTypeRef(implicitTypeRef) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt index 7b8d914dc3a..58e449e83cf 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt @@ -17,10 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol -import org.jetbrains.kotlin.fir.types.FirDynamicTypeRef -import org.jetbrains.kotlin.fir.types.FirErrorTypeRef -import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef -import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.* import org.jetbrains.kotlin.fir.types.impl.* import org.jetbrains.kotlin.name.FqName @@ -62,6 +59,12 @@ fun R.copyWithNewSourceKind(newKind: KtFakeSourceElementKind): annotations += typeRef.annotations } is FirImplicitBuiltinTypeRef -> typeRef.withFakeSource(newKind) + is FirIntersectionTypeRef -> buildIntersectionTypeRef { + source = newSource + isMarkedNullable = typeRef.isMarkedNullable + leftType = typeRef.leftType + rightType = typeRef.rightType + } else -> TODO("Not implemented for ${typeRef::class}") } as R } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/visitors/FirDefaultTransformer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/visitors/FirDefaultTransformer.kt index 23c76cc8f96..c9a9c6f75ac 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/visitors/FirDefaultTransformer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/visitors/FirDefaultTransformer.kt @@ -40,6 +40,10 @@ abstract class FirDefaultTransformer : FirTransformer() { return transformTypeRefWithNullability(userTypeRef, data) } + override fun transformIntersectionTypeRef(intersectionTypeRef: FirIntersectionTypeRef, data: D): FirTypeRef { + return transformTypeRef(intersectionTypeRef, data) + } + override fun transformCallableReferenceAccess( callableReferenceAccess: FirCallableReferenceAccess, data: D diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt index b99ca7420f3..f16fb8ffcae 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt @@ -161,6 +161,7 @@ object FirTreeBuilder : AbstractFirTreeBuilder() { val userTypeRef by element(TypeRef, typeRefWithNullability) val dynamicTypeRef by element(TypeRef, typeRefWithNullability) val functionTypeRef by element(TypeRef, typeRefWithNullability) + val intersectionTypeRef by element(TypeRef, typeRefWithNullability) val implicitTypeRef by element(TypeRef, typeRef) val effectDeclaration by element(Contracts) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 83b5a5f806f..7bfb07209f3 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -643,6 +643,11 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +booleanField("isSuspend") } + intersectionTypeRef.configure { + +field("leftType", typeRef, nullable = true) + +field("rightType", typeRef, nullable = true) + } + thisReceiverExpression.configure { +field("calleeReference", thisReference) +booleanField("isImplicit") diff --git a/compiler/testData/codegen/box/casts/castToDefinitelyNotNullType.kt b/compiler/testData/codegen/box/casts/castToDefinitelyNotNullType.kt index 33ff8db0ef4..3737cda6468 100644 --- a/compiler/testData/codegen/box/casts/castToDefinitelyNotNullType.kt +++ b/compiler/testData/codegen/box/casts/castToDefinitelyNotNullType.kt @@ -3,8 +3,6 @@ // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: WASM // IGNORE_BACKEND: NATIVE -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: Syntax error at (T & Any) fun test(t: T) = t as (T & Any) diff --git a/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt b/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt index 9fcc3059e32..66c27aca001 100644 --- a/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt +++ b/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt @@ -1,7 +1,5 @@ // !LANGUAGE: +DefinitelyNonNullableTypes +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: wrong NOTHING_TO_OVERRIDE at KDerived.foo // FILE: JClass.java import org.jetbrains.annotations.*; diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt index 7116b2f0a18..4731d4970e5 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt @@ -4,11 +4,11 @@ fun foo(x: T, y: T & Any) = x!! fun main() { foo("", "").length - foo("", null).length + foo("", null).length foo(null, "").length foo(null, null).length foo("", "").length foo("", null).length - foo(null, "").length + foo(null, "").length } diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt index 1f0de032f59..f4ebe732911 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt @@ -3,5 +3,5 @@ fun main(x: Collection) { if (x is List & Any) {} - val w: List & Any = null!! + val w: List & Any = null!! } diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt index 948f2f2e62a..33e47c35c47 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt @@ -28,6 +28,6 @@ fun main(x: F, y: F, z: F, w: F, m: F) { w1.foo() w2.foo() - expectNN(m) - expectNN(m!!) + expectNN(m) + expectNN(m!!) } diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt index 089653e66ca..1f9a6be8204 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt @@ -1,18 +1,18 @@ // !LANGUAGE: +DefinitelyNonNullableTypes -fun foo(x: T & Any, y: List & Any) {} +fun foo(x: T & Any, y: List<String & Any> & Any) {} fun bar1(x: F? & Any) {} -fun bar2(x: F & Any?) {} +fun bar2(x: F & Any?) {} fun bar3(x: (F?) & Any) {} fun bar4(x: (F & Any)?) {} -fun bar5(x: F & String) {} +fun bar5(x: F & String) {} -fun bar6(x: F & (F & Any)) {} -fun bar7(x: (F & Any) & Any) {} +fun bar6(x: F & (F & Any)) {} +fun bar7(x: (F & Any) & Any) {} fun bar8(x: (F & Any).() -> Unit) {} fun (F & Any).bar9(x: () -> Unit) {} -fun bar10(x: F & Any & String) {} -fun bar11(x: Double & Any & String) {} +fun bar10(x: F & Any & String) {} +fun bar11(x: Double & Any & String) {} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt deleted file mode 100644 index 407d6f6d652..00000000000 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt +++ /dev/null @@ -1,36 +0,0 @@ -// !LANGUAGE: +DefinitelyNonNullableTypes - -interface A { - fun foo(x: T): T - fun bar(x: T & Any): T & Any -} - -interface B : A { - override fun foo(x: T1): T1 - override fun bar(x: T1 & Any): T1 & Any -} - -interface C : A { - override fun foo(x: T2 & Any): T2 & Any - override fun bar(x: T2): T2 -} - -interface D : A { - override fun foo(x: String?): String? - override fun bar(x: String): String -} - -interface E : A { - override fun foo(x: String): String - override fun bar(x: String): String -} - -interface F : A { - override fun foo(x: String): String - override fun bar(x: String?): String? -} - -interface G : A { - override fun foo(x: T3): T3 - override fun bar(x: T3): T3 -} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt index 49ff65443c1..c958aebdceb 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +DefinitelyNonNullableTypes interface A { diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt deleted file mode 100644 index e6c24d76077..00000000000 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt +++ /dev/null @@ -1,42 +0,0 @@ -// !LANGUAGE: +DefinitelyNonNullableTypes +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated - -// FILE: A.java -import org.jetbrains.annotations.*; - -public interface A { - public T foo(T x) { return x; } - @NotNull - public T bar(@NotNull T x) {} -} - -// FILE: main.kt - -interface B : A { - override fun foo(x: T1): T1 - override fun bar(x: T1 & Any): T1 & Any -} - -interface C : A { - override fun foo(x: T2 & Any): T2 & Any - override fun bar(x: T2): T2 -} - -interface D : A { - override fun foo(x: String?): String? - override fun bar(x: String): String -} - -interface E : A { - override fun foo(x: String): String - override fun bar(x: String): String -} - -interface F : A { - override fun foo(x: String): String - override fun bar(x: String?): String? -} - -interface G : A { - override fun foo(x: T3): T3 - override fun bar(x: T3): T3 -} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt index 4d0839a47ef..8fc72d541dc 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +DefinitelyNonNullableTypes +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated // FILE: A.java diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt index 46dce468ac9..748219cb353 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt @@ -3,12 +3,12 @@ fun foo(x: T, y: T & Any): T & Any = x ?: y fun main() { - foo("", "").length - foo("", null).length - foo(null, "").length - foo(null, null).length + foo("", "").length + foo("", null).length + foo(null, "").length + foo(null, null).length - foo("", "").length - foo("", null).length - foo(null, "").length + foo("", "").length + foo("", null).length + foo(null, "").length } diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinOverridesDefinitelyNonNullable.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinOverridesDefinitelyNonNullable.fir.kt index 79cb67340c5..0f3e5cbd571 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinOverridesDefinitelyNonNullable.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinOverridesDefinitelyNonNullable.fir.kt @@ -30,8 +30,8 @@ interface Q1 : SLRUMap { } interface Q2 : SLRUMap { - override fun takeV(x: X & Any) - override fun takeE(e: E1 & Any) + override fun takeV(x: X & Any) + override fun takeE(e: E1 & Any) override fun takeVList(l: List) override fun takeEList(l2: List) diff --git a/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt b/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt index cca5d161680..68aa0fd3f09 100644 --- a/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/bangbang.fir.ir.txt @@ -30,7 +30,7 @@ FILE fqName: fileName:/bangbang.kt VALUE_PARAMETER name:a index:0 type:X of .test3 BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3 (a: X of .test3): X of .test3 declared in ' - CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=X of .test3 origin=EXCLEXCL + CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type={X of .test3 & Any} origin=EXCLEXCL : X of .test3 arg0: GET_VAR 'a: X of .test3 declared in .test3' type=X of .test3 origin=null FUN name:useString visibility:public modality:FINAL <> (s:kotlin.String) returnType:kotlin.Unit diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.ir.txt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.ir.txt new file mode 100644 index 00000000000..1fd1e707349 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.ir.txt @@ -0,0 +1,75 @@ +FILE fqName: fileName:/implicitCastToNonNull.kt + FUN name:test1 visibility:public modality:FINAL <> (x:kotlin.String?) returnType:kotlin.Int + VALUE_PARAMETER name:x index:0 type:kotlin.String? + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.String?): kotlin.Int declared in ' + WHEN type=kotlin.Int origin=IF + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'x: kotlin.String? declared in .test1' type=kotlin.String? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'x: kotlin.String? declared in .test1' type=kotlin.String? origin=null + FUN name:test2 visibility:public modality:FINAL (x:T of .test2) returnType:kotlin.Int + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.CharSequence?] + VALUE_PARAMETER name:x index:0 type:T of .test2 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test2 (x: T of .test2): kotlin.Int declared in ' + WHEN type=kotlin.Int origin=IF + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'x: T of .test2 declared in .test2' type=T of .test2 origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public abstract fun (): kotlin.Int declared in kotlin.CharSequence' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'x: T of .test2 declared in .test2' type=T of .test2 origin=null + FUN name:test3 visibility:public modality:FINAL (x:kotlin.Any) returnType:kotlin.Int [inline] + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.CharSequence?] + VALUE_PARAMETER name:x index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Any): kotlin.Int [inline] declared in ' + WHEN type=kotlin.Int origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=T of .test3 + GET_VAR 'x: kotlin.Any declared in .test3' type=kotlin.Any origin=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public abstract fun (): kotlin.Int declared in kotlin.CharSequence' type=kotlin.Int origin=GET_PROPERTY + $this: TYPE_OP type={T of .test3 & Any} origin=IMPLICIT_CAST typeOperand={T of .test3 & Any} + GET_VAR 'x: kotlin.Any declared in .test3' type=kotlin.Any origin=null + FUN name:test4 visibility:public modality:FINAL (x:kotlin.Any?) returnType:kotlin.Int [inline] + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.CharSequence] + VALUE_PARAMETER name:x index:0 type:kotlin.Any? + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test4 (x: kotlin.Any?): kotlin.Int [inline] declared in ' + WHEN type=kotlin.Int origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=T of .test4 + GET_VAR 'x: kotlin.Any? declared in .test4' type=kotlin.Any? origin=null + then: CONST Int type=kotlin.Int value=0 + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public abstract fun (): kotlin.Int declared in kotlin.CharSequence' type=kotlin.Int origin=GET_PROPERTY + $this: TYPE_OP type=T of .test4 origin=IMPLICIT_CAST typeOperand=T of .test4 + GET_VAR 'x: kotlin.Any? declared in .test4' type=kotlin.Any? origin=null + FUN name:test5 visibility:public modality:FINAL (x:T of .test5, fn:kotlin.Function1.test5, kotlin.Unit>) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[S of .test5?] + TYPE_PARAMETER name:S index:1 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:x index:0 type:T of .test5 + VALUE_PARAMETER name:fn index:1 type:kotlin.Function1.test5, kotlin.Unit> + BLOCK_BODY + WHEN type=kotlin.Unit origin=IF + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_VAR 'x: T of .test5 declared in .test5' type=T of .test5 origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function1.test5, kotlin.Unit> declared in .test5' type=kotlin.Function1.test5, kotlin.Unit> origin=VARIABLE_AS_FUNCTION + p1: GET_VAR 'x: T of .test5 declared in .test5' type=T of .test5 origin=null diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt new file mode 100644 index 00000000000..38c279849ad --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.fir.kt.txt @@ -0,0 +1,33 @@ +fun test1(x: String?): Int { + return when { + EQEQ(arg0 = x, arg1 = null) -> 0 + else -> x.() + } +} + +fun test2(x: T): Int { + return when { + EQEQ(arg0 = x, arg1 = null) -> 0 + else -> x.() + } +} + +inline fun test3(x: Any): Int { + return when { + x !is T -> 0 + else -> x /*as (T & Any) */.() + } +} + +inline fun test4(x: Any?): Int { + return when { + x !is T -> 0 + else -> x /*as T */.() + } +} + +fun test5(x: T, fn: Function1) { + when { + EQEQ(arg0 = x, arg1 = null).not() -> fn.invoke(p1 = x) + } +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt index 1e8ea10a291..fa482951574 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt +++ b/compiler/testData/ir/irText/expressions/implicitCastToNonNull.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL fun test1(x: String?) = if (x == null) 0 else x.length diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt new file mode 100644 index 00000000000..a51bae85faa --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.ir.txt @@ -0,0 +1,82 @@ +FILE fqName: fileName:/implicitCastToTypeParameter.kt + FUN name:test1 visibility:public modality:FINAL ($receiver:kotlin.Any) returnType:T of .test1? [inline] + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] + $receiver: VALUE_PARAMETER name: type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (): T of .test1? [inline] declared in ' + WHEN type=T of .test1? origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of .test1 + GET_VAR ': kotlin.Any declared in .test1' type=kotlin.Any origin=null + then: TYPE_OP type=T of .test1 origin=IMPLICIT_CAST typeOperand=T of .test1 + GET_VAR ': kotlin.Any declared in .test1' type=kotlin.Any origin=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST Null type=kotlin.Nothing? value=null + CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.Foo> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + PROPERTY name:asT visibility:public modality:FINAL [val] + FUN name: visibility:public modality:FINAL ($receiver:.Foo.>) returnType:T of .? [inline] + correspondingProperty: PROPERTY name:asT visibility:public modality:FINAL [val] + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] + $receiver: VALUE_PARAMETER name: type:.Foo.> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): T of .? [inline] declared in ' + WHEN type=T of .? origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of . + GET_VAR ': .Foo.> declared in .' type=.Foo.> origin=null + then: TYPE_OP type=T of . origin=IMPLICIT_CAST typeOperand=T of . + GET_VAR ': .Foo.> declared in .' type=.Foo.> origin=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST Null type=kotlin.Nothing? value=null + CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Bar.Bar> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.Bar.Bar> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:test visibility:public modality:FINAL <> ($this:.Bar.Bar>, arg:kotlin.Any) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.Bar.Bar> + VALUE_PARAMETER name:arg index:0 type:kotlin.Any + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=T of .Bar origin=CAST typeOperand=T of .Bar + GET_VAR 'arg: kotlin.Any declared in .Bar.test' type=kotlin.Any origin=null + CALL 'public final fun useT (t: T of .Bar): kotlin.Unit declared in .Bar' type=kotlin.Unit origin=null + $this: GET_VAR ': .Bar.Bar> declared in .Bar.test' type=.Bar.Bar> origin=null + t: TYPE_OP type={T of .Bar & Any} origin=IMPLICIT_CAST typeOperand={T of .Bar & Any} + GET_VAR 'arg: kotlin.Any declared in .Bar.test' type=kotlin.Any origin=null + FUN name:useT visibility:public modality:FINAL <> ($this:.Bar.Bar>, t:T of .Bar) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.Bar.Bar> + VALUE_PARAMETER name:t index:0 type:T of .Bar + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt new file mode 100644 index 00000000000..19fce2fad30 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.kt.txt @@ -0,0 +1,35 @@ +inline fun Any.test1(): T? { + return when { + is T -> /*as T */ + else -> null + } +} + +interface Foo { + +} + +val Foo.asT: T? + inline get(): T? { + return when { + is T -> /*as T */ + else -> null + } + } + +class Bar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun test(arg: Any) { + arg as T /*~> Unit */ + .useT(t = arg /*as (T & Any) */) + } + + fun useT(t: T) { + } + +} diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt index 3c87e7b8455..5e9a09ea788 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL inline fun Any.test1(): T? = if (this is T) this else null diff --git a/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.ir.txt b/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.ir.txt index 92b291fe2c2..308100f7075 100644 --- a/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/AbstractMutableMap.fir.ir.txt @@ -77,14 +77,14 @@ FILE fqName: fileName:/AbstractMutableMap.kt VALUE_PARAMETER name:p0 index:0 type:@[EnhancedNullability] java.util.function.BiFunction.MyMap, in @[EnhancedNullability] V of .MyMap, out @[EnhancedNullability] V of .MyMap> FUN FAKE_OVERRIDE name:merge visibility:public modality:OPEN <> ($this:kotlin.collections.MutableMap, p0:@[EnhancedNullability] K of .MyMap, p1:@[EnhancedNullability] V of .MyMap, p2:@[EnhancedNullability] java.util.function.BiFunction.MyMap, in @[EnhancedNullability] V of .MyMap, out V of .MyMap?>) returnType:V of .MyMap? [fake_override] overridden: - public open fun merge (p0: @[EnhancedNullability] K of kotlin.collections.AbstractMutableMap, p1: @[EnhancedNullability] V of kotlin.collections.AbstractMutableMap, p2: @[EnhancedNullability] java.util.function.BiFunction): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap + public open fun merge (p0: @[EnhancedNullability] K of kotlin.collections.AbstractMutableMap, p1: @[EnhancedNullability] {@[EnhancedNullability] V of kotlin.collections.AbstractMutableMap & Any}, p2: @[EnhancedNullability] java.util.function.BiFunction): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap $this: VALUE_PARAMETER name: type:kotlin.collections.MutableMap VALUE_PARAMETER name:p0 index:0 type:@[EnhancedNullability] K of .MyMap VALUE_PARAMETER name:p1 index:1 type:@[EnhancedNullability] V of .MyMap VALUE_PARAMETER name:p2 index:2 type:@[EnhancedNullability] java.util.function.BiFunction.MyMap, in @[EnhancedNullability] V of .MyMap, out V of .MyMap?> FUN FAKE_OVERRIDE name:computeIfPresent visibility:public modality:OPEN <> ($this:kotlin.collections.MutableMap, p0:@[EnhancedNullability] K of .MyMap, p1:@[EnhancedNullability] java.util.function.BiFunction.MyMap, in @[EnhancedNullability] V of .MyMap, out V of .MyMap?>) returnType:V of .MyMap? [fake_override] overridden: - public open fun computeIfPresent (p0: @[EnhancedNullability] K of kotlin.collections.AbstractMutableMap, p1: @[EnhancedNullability] java.util.function.BiFunction): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap + public open fun computeIfPresent (p0: @[EnhancedNullability] K of kotlin.collections.AbstractMutableMap, p1: @[EnhancedNullability] java.util.function.BiFunction): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap $this: VALUE_PARAMETER name: type:kotlin.collections.MutableMap VALUE_PARAMETER name:p0 index:0 type:@[EnhancedNullability] K of .MyMap VALUE_PARAMETER name:p1 index:1 type:@[EnhancedNullability] java.util.function.BiFunction.MyMap, in @[EnhancedNullability] V of .MyMap, out V of .MyMap?> diff --git a/compiler/testData/ir/irText/types/definitelyNonNull.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNonNull.fir.ir.txt new file mode 100644 index 00000000000..802ae35bf24 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNull.fir.ir.txt @@ -0,0 +1,45 @@ +FILE fqName: fileName:/definitelyNonNull.kt + FUN name:elvisLike visibility:public modality:FINAL (x:T of .elvisLike, y:{T of .elvisLike & Any}) returnType:{T of .elvisLike & Any} + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:x index:0 type:T of .elvisLike + VALUE_PARAMETER name:y index:1 type:{T of .elvisLike & Any} + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun elvisLike (x: T of .elvisLike, y: {T of .elvisLike & Any}): {T of .elvisLike & Any} declared in ' + BLOCK type={T of .elvisLike & Any} origin=ELVIS + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:T of .elvisLike [val] + GET_VAR 'x: T of .elvisLike declared in .elvisLike' type=T of .elvisLike origin=null + WHEN type={T of .elvisLike & Any} origin=ELVIS + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp_0: T of .elvisLike [val] declared in .elvisLike' type=T of .elvisLike origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: GET_VAR 'y: {T of .elvisLike & Any} declared in .elvisLike' type={T of .elvisLike & Any} origin=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: GET_VAR 'val tmp_0: T of .elvisLike [val] declared in .elvisLike' type=T of .elvisLike origin=null + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public final fun elvisLike (x: T of .elvisLike, y: {T of .elvisLike & Any}): {T of .elvisLike & Any} declared in ' type=kotlin.String origin=null + : kotlin.String + x: CONST String type=kotlin.String value="" + y: CONST String type=kotlin.String value="" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public final fun elvisLike (x: T of .elvisLike, y: {T of .elvisLike & Any}): {T of .elvisLike & Any} declared in ' type=kotlin.String origin=null + : kotlin.String? + x: CONST Null type=kotlin.Nothing? value=null + y: CONST String type=kotlin.String value="" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public final fun elvisLike (x: T of .elvisLike, y: {T of .elvisLike & Any}): {T of .elvisLike & Any} declared in ' type=kotlin.String origin=null + : kotlin.String + x: CONST String type=kotlin.String value="" + y: CONST String type=kotlin.String value="" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public final fun elvisLike (x: T of .elvisLike, y: {T of .elvisLike & Any}): {T of .elvisLike & Any} declared in ' type=kotlin.String origin=null + : kotlin.String? + x: CONST Null type=kotlin.Nothing? value=null + y: CONST String type=kotlin.String value="" diff --git a/compiler/testData/ir/irText/types/definitelyNonNull.fir.kt.txt b/compiler/testData/ir/irText/types/definitelyNonNull.fir.kt.txt new file mode 100644 index 00000000000..d44e7ccd752 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNull.fir.kt.txt @@ -0,0 +1,17 @@ +fun elvisLike(x: T, y: (T & Any)): (T & Any) { + return { // BLOCK + val : T = x + when { + EQEQ(arg0 = , arg1 = null) -> y + else -> + } + } +} + +fun main() { + elvisLike(x = "", y = "").() /*~> Unit */ + elvisLike(x = null, y = "").() /*~> Unit */ + elvisLike(x = "", y = "").() /*~> Unit */ + elvisLike(x = null, y = "").() /*~> Unit */ +} + diff --git a/compiler/testData/ir/irText/types/definitelyNonNull.kt b/compiler/testData/ir/irText/types/definitelyNonNull.kt index 7ea07624c76..32abde4820c 100644 --- a/compiler/testData/ir/irText/types/definitelyNonNull.kt +++ b/compiler/testData/ir/irText/types/definitelyNonNull.kt @@ -1,5 +1,4 @@ //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY fun elvisLike(x: T, y: T & Any): T & Any = x ?: y diff --git a/compiler/testData/ir/irText/types/definitelyNonNullOverride.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNonNullOverride.fir.ir.txt new file mode 100644 index 00000000000..ebeb1707528 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNullOverride.fir.ir.txt @@ -0,0 +1,83 @@ +FILE fqName: fileName:/definitelyNonNullOverride.kt + CLASS CLASS name:B modality:OPEN visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B.B> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.B.B> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:OPEN visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:OPEN <> ($this:.B.B>, t:T of .B) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:t index:0 type:T of .B + BLOCK_BODY + FUN name:bar visibility:public modality:OPEN <> ($this:.B.B>, t:T of .B) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:t index:0 type:T of .B + BLOCK_BODY + FUN name:qux visibility:public modality:OPEN <> ($this:.B.B>, b:.B.B>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:b index:0 type:.B.B> + BLOCK_BODY + FUN name:six visibility:public modality:OPEN ($this:.B.B>, t:T of .B, q:F of .B.six) returnType:kotlin.Unit + TYPE_PARAMETER name:F index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:t index:0 type:T of .B + VALUE_PARAMETER name:q index:1 type:F of .B.six + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:D modality:FINAL visibility:public superTypes:[.B<{T of .D & Any}>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.D.D> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.D.D> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .B' + : {T of .D & Any} + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:D modality:FINAL visibility:public superTypes:[.B<{T of .D & Any}>]' + FUN name:foo visibility:public modality:FINAL <> ($this:.D.D>, t:{T of .D & Any}) returnType:kotlin.Unit + overridden: + public open fun foo (t: T of .B): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.D.D> + VALUE_PARAMETER name:t index:0 type:{T of .D & Any} + BLOCK_BODY + FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:.B.B>, t:{T of .D & Any}) returnType:kotlin.Unit [fake_override] + overridden: + public open fun bar (t: T of .B): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:t index:0 type:{T of .D & Any} + FUN FAKE_OVERRIDE name:qux visibility:public modality:OPEN <> ($this:.B.B>, b:.B<{T of .D & Any}>) returnType:kotlin.Unit [fake_override] + overridden: + public open fun qux (b: .B.B>): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:b index:0 type:.B<{T of .D & Any}> + FUN FAKE_OVERRIDE name:six visibility:public modality:OPEN ($this:.B.B>, t:{T of .D & Any}, q:F of .D.six) returnType:kotlin.Unit [fake_override] + overridden: + public open fun six (t: T of .B, q: F of .B.six): kotlin.Unit declared in .B + TYPE_PARAMETER name:F index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:t index:0 type:{T of .D & Any} + VALUE_PARAMETER name:q index:1 type:F of .D.six + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .B + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .B + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .B + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/types/definitelyNonNullOverride.kt b/compiler/testData/ir/irText/types/definitelyNonNullOverride.kt index d7c4e29b092..c1b58946d85 100644 --- a/compiler/testData/ir/irText/types/definitelyNonNullOverride.kt +++ b/compiler/testData/ir/irText/types/definitelyNonNullOverride.kt @@ -1,5 +1,4 @@ //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY // SKIP_KT_DUMP open class B { diff --git a/compiler/testData/ir/irText/types/definitelyNonNullSAM.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNonNullSAM.fir.ir.txt new file mode 100644 index 00000000000..63d6a729b03 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNullSAM.fir.ir.txt @@ -0,0 +1,223 @@ +FILE fqName: fileName:/definitelyNonNullSAM.kt + CLASS INTERFACE name:FIn modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.FIn.FIn> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + FUN name:f visibility:public modality:ABSTRACT <> ($this:.FIn.FIn>, x:T of .FIn) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FIn.FIn> + VALUE_PARAMETER name:x index:0 type:T of .FIn + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test.Test> + TYPE_PARAMETER name:S index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.Test.Test> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:FINAL <> ($this:.Test.Test>) returnType:.FIn<{S of .Test & Any}> + $this: VALUE_PARAMETER name: type:.Test.Test> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (): .FIn<{S of .Test & Any}> declared in .Test' + TYPE_OP type=.FIn<{S of .Test & Any}> origin=SAM_CONVERSION typeOperand=.FIn<{S of .Test & Any}> + FUN_EXPR type=kotlin.Function1<{S of .Test & Any}, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (sx:{S of .Test & Any}) returnType:kotlin.Unit + VALUE_PARAMETER name:sx index:0 type:{S of .Test & Any} + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String origin=null + $this: GET_VAR 'sx: {S of .Test & Any} declared in .Test.foo.' type={S of .Test & Any} origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:bar visibility:public modality:FINAL () returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + BLOCK type=.bar..bar> origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[.FIn<{T of .bar & Any}>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.bar..bar> + CONSTRUCTOR visibility:private <> () returnType:.bar..bar> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.FIn<{T of .bar & Any}>]' + FUN name:f visibility:public modality:FINAL <> ($this:.bar..bar>, sx:{T of .bar & Any}) returnType:kotlin.Unit + overridden: + public abstract fun f (x: T of .FIn): kotlin.Unit declared in .FIn + $this: VALUE_PARAMETER name: type:.bar..bar> + VALUE_PARAMETER name:sx index:0 type:{T of .bar & Any} + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String origin=null + $this: GET_VAR 'sx: {T of .bar & Any} declared in .bar..f' type={T of .bar & Any} origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .FIn + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .FIn + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .FIn + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'private constructor () [primary] declared in .bar.' type=.bar..bar> origin=OBJECT_LITERAL + CLASS INTERFACE name:I1 modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I1.I1> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + PROPERTY name:l visibility:public modality:ABSTRACT [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.I1.I1>) returnType:@[ExtensionFunctionType] kotlin.Function1.I1, kotlin.Unit> + correspondingProperty: PROPERTY name:l visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.I1.I1> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:I2 modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I2.I2> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + PROPERTY name:sam visibility:public modality:ABSTRACT [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.I2.I2>) returnType:.FIn.I2> + correspondingProperty: PROPERTY name:sam visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.I2.I2> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:AC modality:ABSTRACT visibility:public superTypes:[.I1.AC>; .I2.AC>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.AC.AC> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.AC.AC> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:AC modality:ABSTRACT visibility:public superTypes:[.I1.AC>; .I2.AC>]' + PROPERTY name:sam visibility:public modality:OPEN [val] + overridden: + public abstract sam: .FIn.I2> [val] + FIELD PROPERTY_BACKING_FIELD name:sam type:.FIn.AC> visibility:private [final] + EXPRESSION_BODY + TYPE_OP type=.FIn.AC> origin=SAM_CONVERSION typeOperand=.FIn.AC> + CALL 'public abstract fun (): @[ExtensionFunctionType] kotlin.Function1.AC, kotlin.Unit> [fake_override] declared in .AC' type=@[ExtensionFunctionType] kotlin.Function1.AC, kotlin.Unit> origin=GET_PROPERTY + $this: GET_VAR ': .AC.AC> declared in .AC' type=.AC.AC> origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:OPEN <> ($this:.AC.AC>) returnType:.FIn.AC> + correspondingProperty: PROPERTY name:sam visibility:public modality:OPEN [val] + overridden: + public abstract fun (): .FIn.I2> declared in .I2 + $this: VALUE_PARAMETER name: type:.AC.AC> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): .FIn.AC> declared in .AC' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:sam type:.FIn.AC> visibility:private [final]' type=.FIn.AC> origin=null + receiver: GET_VAR ': .AC.AC> declared in .AC.' type=.AC.AC> origin=null + PROPERTY FAKE_OVERRIDE name:l visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract l: @[ExtensionFunctionType] kotlin.Function1.I1, kotlin.Unit> [val] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.I1.I1>) returnType:@[ExtensionFunctionType] kotlin.Function1.AC, kotlin.Unit> [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:l visibility:public modality:ABSTRACT [fake_override,val] + overridden: + public abstract fun (): @[ExtensionFunctionType] kotlin.Function1.I1, kotlin.Unit> declared in .I1 + $this: VALUE_PARAMETER name: type:.I1.I1> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .I1 + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .I2 + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .I1 + public open fun hashCode (): kotlin.Int [fake_override] declared in .I2 + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .I1 + public open fun toString (): kotlin.String [fake_override] declared in .I2 + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:AD modality:ABSTRACT visibility:public superTypes:[.AC<{T of .AD & Any}>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.AD.AD> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.AD.AD> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .AC' + : {T of .AD & Any} + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:AD modality:ABSTRACT visibility:public superTypes:[.AC<{T of .AD & Any}>]' + PROPERTY name:l visibility:public modality:OPEN [val] + overridden: + public abstract l: @[ExtensionFunctionType] kotlin.Function1.AC, kotlin.Unit> [fake_override,val] + FIELD PROPERTY_BACKING_FIELD name:l type:@[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> visibility:private [final] + EXPRESSION_BODY + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:{T of .AD & Any}) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:{T of .AD & Any} + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .AD.l' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:OPEN <> ($this:.AD.AD>) returnType:@[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> + correspondingProperty: PROPERTY name:l visibility:public modality:OPEN [val] + overridden: + public abstract fun (): @[ExtensionFunctionType] kotlin.Function1.AC, kotlin.Unit> [fake_override] declared in .AC + $this: VALUE_PARAMETER name: type:.AD.AD> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): @[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> declared in .AD' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:l type:@[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> visibility:private [final]' type=@[ExtensionFunctionType] kotlin.Function1<{T of .AD & Any}, kotlin.Unit> origin=null + receiver: GET_VAR ': .AD.AD> declared in .AD.' type=.AD.AD> origin=null + PROPERTY FAKE_OVERRIDE name:sam visibility:public modality:OPEN [fake_override,val] + overridden: + public open sam: .FIn.AC> [val] + FUN FAKE_OVERRIDE name: visibility:public modality:OPEN <> ($this:.AC.AC>) returnType:.FIn<{T of .AD & Any}> [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:sam visibility:public modality:OPEN [fake_override,val] + overridden: + public open fun (): .FIn.AC> declared in .AC + $this: VALUE_PARAMETER name: type:.AC.AC> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .AC + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .AC + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .AC + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/types/definitelyNonNullSAM.kt b/compiler/testData/ir/irText/types/definitelyNonNullSAM.kt index 1d93c4c4406..86d3aa734a0 100644 --- a/compiler/testData/ir/irText/types/definitelyNonNullSAM.kt +++ b/compiler/testData/ir/irText/types/definitelyNonNullSAM.kt @@ -1,5 +1,4 @@ //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY // SKIP_KT_DUMP fun interface FIn { diff --git a/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.ir.txt new file mode 100644 index 00000000000..e7768827a97 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.ir.txt @@ -0,0 +1,27 @@ +FILE fqName: fileName:/main.kt + CLASS INTERFACE name:B modality:ABSTRACT visibility:public superTypes:[.A.B>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B.B> + TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?] + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.B.B>, x:T1 of .B) returnType:T1 of .B + overridden: + public abstract fun foo (x: @[FlexibleNullability] T of .A?): @[FlexibleNullability] T of .A? declared in .A + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:x index:0 type:T1 of .B + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.B.B>, x:{T1 of .B & Any}) returnType:{T1 of .B & Any} + overridden: + public abstract fun bar (x: @[EnhancedNullability] {@[EnhancedNullability] T of .A & Any}): @[EnhancedNullability] {@[EnhancedNullability] T of .A & Any} declared in .A + $this: VALUE_PARAMETER name: type:.B.B> + VALUE_PARAMETER name:x index:0 type:{T1 of .B & Any} + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .A + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .A + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .A + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.kt.txt b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.kt.txt new file mode 100644 index 00000000000..2e4d12b9033 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.fir.kt.txt @@ -0,0 +1,5 @@ +interface B : A { + abstract override fun foo(x: T1): T1 + abstract override fun bar(x: (T1 & Any)): (T1 & Any) + +} diff --git a/compiler/testData/ir/irText/types/definitelyNonNullWithJava.kt b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.kt index 1732d950fed..55403195688 100644 --- a/compiler/testData/ir/irText/types/definitelyNonNullWithJava.kt +++ b/compiler/testData/ir/irText/types/definitelyNonNullWithJava.kt @@ -1,6 +1,5 @@ //!LANGUAGE: +DefinitelyNonNullableTypes // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: ANY // FILE: A.java import org.jetbrains.annotations.*; diff --git a/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.ir.txt new file mode 100644 index 00000000000..abf8b65ac74 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.ir.txt @@ -0,0 +1,95 @@ +FILE fqName: fileName:/definitelyNotNullAsArgument.kt + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I.I> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + FUN name:input visibility:public modality:ABSTRACT <> ($this:.I.I>, t:T of .I) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.I.I> + VALUE_PARAMETER name:t index:0 type:T of .I + FUN name:output visibility:public modality:ABSTRACT <> ($this:.I.I>) returnType:T of .I + $this: VALUE_PARAMETER name: type:.I.I> + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:foo visibility:public modality:FINAL (i:.I<{T of .foo & Any}>) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:i index:0 type:.I<{T of .foo & Any}> + BLOCK_BODY + CALL 'public abstract fun input (t: T of .I): kotlin.Unit declared in .I' type=kotlin.Unit origin=null + $this: GET_VAR 'i: .I<{T of .foo & Any}> declared in .foo' type=.I<{T of .foo & Any}> origin=null + t: CALL 'public abstract fun output (): T of .I declared in .I' type={T of .foo & Any} origin=null + $this: GET_VAR 'i: .I<{T of .foo & Any}> declared in .foo' type=.I<{T of .foo & Any}> origin=null + FUN name:bar visibility:public modality:FINAL (i:.I.bar & Any}>) returnType:{T of .bar & Any} + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:i index:0 type:.I.bar & Any}> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun bar (i: .I.bar & Any}>): {T of .bar & Any} declared in ' + CALL 'public abstract fun output (): T of .I declared in .I' type={T of .bar & Any} origin=null + $this: GET_VAR 'i: .I.bar & Any}> declared in .bar' type=.I.bar & Any}> origin=null + FUN name:qux visibility:public modality:FINAL (t:T of .qux, i:.I.qux & Any}>) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:t index:0 type:T of .qux + VALUE_PARAMETER name:i index:1 type:.I.qux & Any}> + BLOCK_BODY + CALL 'public abstract fun input (t: T of .I): kotlin.Unit declared in .I' type=kotlin.Unit origin=null + $this: GET_VAR 'i: .I.qux & Any}> declared in .qux' type=.I.qux & Any}> origin=null + t: CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type={T of .qux & Any} origin=EXCLEXCL + : T of .qux + arg0: GET_VAR 't: T of .qux declared in .qux' type=T of .qux origin=null + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[.I<{TT of .C & Any}>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C.C> + TYPE_PARAMETER name:TT index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> (t:TT of .C) returnType:.C.C> [primary] + VALUE_PARAMETER name:t index:0 type:TT of .C + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[.I<{TT of .C & Any}>]' + PROPERTY name:t visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:t type:TT of .C visibility:private [final] + EXPRESSION_BODY + GET_VAR 't: TT of .C declared in .C.' type=TT of .C origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.C.C>) returnType:TT of .C + correspondingProperty: PROPERTY name:t visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.C.C> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): TT of .C declared in .C' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:t type:TT of .C visibility:private [final]' type=TT of .C origin=null + receiver: GET_VAR ': .C.C> declared in .C.' type=.C.C> origin=null + FUN name:input visibility:public modality:FINAL <> ($this:.C.C>, t:{TT of .C & Any}) returnType:kotlin.Unit + overridden: + public abstract fun input (t: T of .I): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.C.C> + VALUE_PARAMETER name:t index:0 type:{TT of .C & Any} + BLOCK_BODY + FUN name:output visibility:public modality:FINAL <> ($this:.C.C>) returnType:{TT of .C & Any} + overridden: + public abstract fun output (): T of .I declared in .I + $this: VALUE_PARAMETER name: type:.C.C> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun output (): {TT of .C & Any} declared in .C' + CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type={TT of .C & Any} origin=EXCLEXCL + : TT of .C + arg0: CALL 'public final fun (): TT of .C declared in .C' type=TT of .C origin=GET_PROPERTY + $this: GET_VAR ': .C.C> declared in .C.output' type=.C.C> origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.kt.txt b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.kt.txt new file mode 100644 index 00000000000..d10d623fc1c --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.fir.kt.txt @@ -0,0 +1,37 @@ +interface I { + abstract fun input(t: T) + abstract fun output(): T + +} + +fun foo(i: I<(T & Any)>) { + i.input(t = i.output()) +} + +fun bar(i: I): (T & Any) { + return i.output() +} + +fun qux(t: T, i: I) { + i.input(t = CHECK_NOT_NULL(arg0 = t)) +} + +class C : I<(TT & Any)> { + constructor(t: TT) /* primary */ { + super/*Any*/() + /* () */ + + } + + val t: TT + field = t + get + + override fun input(t: (TT & Any)) { + } + + override fun output(): (TT & Any) { + return CHECK_NOT_NULL(arg0 = .()) + } + +} diff --git a/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.kt b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.kt index 79d74cf8023..9ea8017bc4a 100644 --- a/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.kt +++ b/compiler/testData/ir/irText/types/definitelyNotNullAsArgument.kt @@ -1,5 +1,4 @@ //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY interface I { fun input(t: T) diff --git a/compiler/testData/ir/irText/types/definitelyNotNullAsReceiver.kt b/compiler/testData/ir/irText/types/definitelyNotNullAsReceiver.kt index 3e60fac279b..50020b8ad47 100644 --- a/compiler/testData/ir/irText/types/definitelyNotNullAsReceiver.kt +++ b/compiler/testData/ir/irText/types/definitelyNotNullAsReceiver.kt @@ -1,5 +1,5 @@ +// FIR_IDENTICAL //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY fun (T & Any).foo() {} fun foo(l: (T & Any) -> Unit) {} diff --git a/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.fir.ir.txt b/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.fir.ir.txt new file mode 100644 index 00000000000..b660d11c090 --- /dev/null +++ b/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.fir.ir.txt @@ -0,0 +1,80 @@ +FILE fqName: fileName:/definitelyNotNullWithIntersection1.kt + CLASS CLASS name:In modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.In.In> + TYPE_PARAMETER name:I index:0 variance:in superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.In.In> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:In modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:select visibility:public modality:FINAL (x:S of .select, y:S of .select, z:S of .select) returnType:S of .select + TYPE_PARAMETER name:S index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:x index:0 type:S of .select + VALUE_PARAMETER name:y index:1 type:S of .select + VALUE_PARAMETER name:z index:2 type:S of .select + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun select (x: S of .select, y: S of .select, z: S of .select): S of .select declared in ' + GET_VAR 'x: S of .select declared in .select' type=S of .select origin=null + FUN name:foo visibility:public modality:FINAL (a:kotlin.Array<.In<{T of .foo & Any}>>, b:kotlin.Array<.In>, c:kotlin.Array<.In.foo>>) returnType:kotlin.Boolean + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:a index:0 type:kotlin.Array<.In<{T of .foo & Any}>> + VALUE_PARAMETER name:b index:1 type:kotlin.Array<.In> + VALUE_PARAMETER name:c index:2 type:kotlin.Array<.In.foo>> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.Array<.In<{T of .foo & Any}>>, b: kotlin.Array<.In>, c: kotlin.Array<.In.foo>>): kotlin.Boolean declared in ' + CALL 'public final fun ofType (y: kotlin.Any?): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null + : kotlin.Any + $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=.In origin=null + $this: CALL 'public final fun select (x: S of .select, y: S of .select, z: S of .select): S of .select declared in ' type=kotlin.Array.In> origin=null + : kotlin.Array.In> + x: GET_VAR 'a: kotlin.Array<.In<{T of .foo & Any}>> declared in .foo' type=kotlin.Array<.In<{T of .foo & Any}>> origin=null + y: GET_VAR 'b: kotlin.Array<.In> declared in .foo' type=kotlin.Array<.In> origin=null + z: GET_VAR 'c: kotlin.Array<.In.foo>> declared in .foo' type=kotlin.Array<.In.foo>> origin=null + index: CONST Int type=kotlin.Int value=0 + y: CONST Boolean type=kotlin.Boolean value=true + FUN name:ofType visibility:public modality:FINAL ($receiver:.In.ofType>, y:kotlin.Any?) returnType:kotlin.Boolean [inline] + TYPE_PARAMETER name:K index:0 variance: superTypes:[kotlin.Any?] + $receiver: VALUE_PARAMETER name: type:.In.ofType> + VALUE_PARAMETER name:y index:0 type:kotlin.Any? + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun ofType (y: kotlin.Any?): kotlin.Boolean [inline] declared in ' + TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=K of .ofType + GET_VAR 'y: kotlin.Any? declared in .ofType' type=kotlin.Any? origin=null + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:a1 type:kotlin.Array<.In> [val] + CALL 'public final fun arrayOf (vararg elements: T of kotlin.arrayOf): kotlin.Array [inline] declared in kotlin' type=kotlin.Array<.In> origin=null + : .In + elements: VARARG type=kotlin.Array.In> varargElementType=.In + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .In' type=.In origin=null + : kotlin.Int + VAR name:a2 type:kotlin.Array<.In> [val] + CALL 'public final fun arrayOf (vararg elements: T of kotlin.arrayOf): kotlin.Array [inline] declared in kotlin' type=kotlin.Array<.In> origin=null + : .In + elements: VARARG type=kotlin.Array.In> varargElementType=.In + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .In' type=.In origin=null + : kotlin.String + VAR name:a3 type:kotlin.Array<.In> [val] + CALL 'public final fun arrayOf (vararg elements: T of kotlin.arrayOf): kotlin.Array [inline] declared in kotlin' type=kotlin.Array<.In> origin=null + : .In + elements: VARARG type=kotlin.Array.In> varargElementType=.In + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .In' type=.In origin=null + : kotlin.Int + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun foo (a: kotlin.Array<.In<{T of .foo & Any}>>, b: kotlin.Array<.In>, c: kotlin.Array<.In.foo>>): kotlin.Boolean declared in ' type=kotlin.Boolean origin=null + : kotlin.Int + a: GET_VAR 'val a1: kotlin.Array<.In> [val] declared in .test' type=kotlin.Array<.In> origin=null + b: GET_VAR 'val a2: kotlin.Array<.In> [val] declared in .test' type=kotlin.Array<.In> origin=null + c: GET_VAR 'val a3: kotlin.Array<.In> [val] declared in .test' type=kotlin.Array<.In> origin=null diff --git a/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt b/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt index ddbec060fec..f7d9adb3175 100644 --- a/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt +++ b/compiler/testData/ir/irText/types/definitelyNotNullWithIntersection1.kt @@ -1,5 +1,4 @@ //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY // SKIP_KT_DUMP class In diff --git a/compiler/testData/ir/irText/types/typeCheckOnDefinitelyNotNull.kt b/compiler/testData/ir/irText/types/typeCheckOnDefinitelyNotNull.kt index 29568831ed3..0c8dbd5dd83 100644 --- a/compiler/testData/ir/irText/types/typeCheckOnDefinitelyNotNull.kt +++ b/compiler/testData/ir/irText/types/typeCheckOnDefinitelyNotNull.kt @@ -1,5 +1,5 @@ +// FIR_IDENTICAL //!LANGUAGE: +DefinitelyNonNullableTypes -// IGNORE_BACKEND_FIR: ANY fun asFoo(t: T) = t as (T & Any) fun safeAsFoo(t: T) = t as? (T & Any)