[FIR] Add FirCheckNotNullCall converted to CHECK_NOT_NULL intrinsic

function call.
This commit is contained in:
Mark Punzalan
2019-12-02 22:57:24 -08:00
committed by Dmitriy Novozhilov
parent 6bc0fe121a
commit 692a83f7bb
72 changed files with 363 additions and 355 deletions
@@ -17,6 +17,10 @@ object SyntheticCallableId {
FqName("_synthetic"),
Name.identifier("TRY_CALL")
)
val CHECK_NOT_NULL = CallableId(
FqName("_synthetic"),
Name.identifier("CHECK_NOT_NULL_CALL")
)
val ID = CallableId(
FqName("_synthetic"),
Name.identifier("ID_CALL")
@@ -45,11 +45,8 @@ import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.ClassId
@@ -1289,6 +1286,20 @@ class Fir2IrVisitor(
}
}
override fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: Any?): IrElement {
return checkNotNullCall.convertWithOffsets { startOffset, endOffset ->
IrCallImpl(
startOffset, endOffset,
checkNotNullCall.typeRef.toIrType(session, declarationStorage),
irBuiltIns.checkNotNullSymbol,
IrStatementOrigin.EXCLEXCL
).apply {
putTypeArgument(0, checkNotNullCall.argument.typeRef.toIrType(session, declarationStorage).makeNotNull())
putValueArgument(0, checkNotNullCall.argument.toIrExpression())
}
}
}
override fun visitGetClassCall(getClassCall: FirGetClassCall, data: Any?): IrElement {
return getClassCall.convertWithOffsets { startOffset, endOffset ->
IrGetClassImpl(
@@ -306,28 +306,33 @@ class ExpressionsConverter(
}
val operationToken = operationTokenName.getOperationSymbol()
if (operationToken == EXCLEXCL) {
return argument.bangBangToWhen(null) { getAsFirExpression(this, it) }
}
val conventionCallName = operationToken.toUnaryName()
return if (conventionCallName != null) {
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
return generateIncrementOrDecrementBlock(
null,
argument,
callName = conventionCallName,
prefix = unaryExpression.tokenType == PREFIX_EXPRESSION
) { getAsFirExpression(this) }
return when {
operationToken == EXCLEXCL -> {
FirCheckNotNullCallImpl(null).apply {
arguments += getAsFirExpression<FirExpression>(argument, "No operand")
}
}
FirFunctionCallImpl(null).apply {
calleeReference = FirSimpleNamedReference(null, conventionCallName, null)
explicitReceiver = getAsFirExpression(argument, "No operand")
conventionCallName != null -> {
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
return generateIncrementOrDecrementBlock(
null,
argument,
callName = conventionCallName,
prefix = unaryExpression.tokenType == PREFIX_EXPRESSION
) { getAsFirExpression(this) }
}
FirFunctionCallImpl(null).apply {
calleeReference = FirSimpleNamedReference(null, conventionCallName, null)
explicitReceiver = getAsFirExpression(argument, "No operand")
}
}
} else {
val firOperation = operationToken.toFirOperation()
FirOperatorCallImpl(null, firOperation).apply {
arguments += getAsFirExpression<FirExpression>(argument, "No operand")
else -> {
val firOperation = operationToken.toFirOperation()
FirOperatorCallImpl(null, firOperation).apply {
arguments += getAsFirExpression<FirExpression>(argument, "No operand")
}
}
}
}
@@ -167,18 +167,6 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
?: emptyList()
}
fun T?.bangBangToWhen(parent: KtUnaryExpression?, convert: T?.(String) -> FirExpression): FirWhenExpression {
val source = parent.getSourceOrNull()
return this.convert("No operand").generateNotNullOrOther(
session,
FirThrowExpressionImpl(
source, FirFunctionCallImpl(source).apply {
calleeReference = FirSimpleNamedReference(source, KNPE, null)
}
), "bangbang", source
)
}
fun FirAbstractLoop.configure(generateBlock: () -> FirBlock): FirAbstractLoop {
label = context.firLabels.pop()
context.firLoops += this
@@ -1222,28 +1222,33 @@ class RawFirBuilder(session: FirSession, val stubMode: Boolean) : BaseFirBuilder
override fun visitUnaryExpression(expression: KtUnaryExpression, data: Unit): FirElement {
val operationToken = expression.operationToken
val argument = expression.baseExpression
if (operationToken == EXCLEXCL) {
return expression.baseExpression.bangBangToWhen(expression) { (this as KtExpression).toFirExpression(it) }
}
val conventionCallName = operationToken.toUnaryName()
return if (conventionCallName != null) {
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
return generateIncrementOrDecrementBlock(
expression, argument,
callName = conventionCallName,
prefix = expression is KtPrefixExpression
) { (this as KtExpression).toFirExpression("Incorrect expression inside inc/dec") }
return when {
operationToken == EXCLEXCL -> {
FirCheckNotNullCallImpl(expression.toFirSourceElement()).apply {
arguments += argument.toFirExpression("No operand")
}
}
FirFunctionCallImpl(expression.toFirSourceElement()).apply {
calleeReference = FirSimpleNamedReference(
expression.operationReference.toFirSourceElement(), conventionCallName, null
)
explicitReceiver = argument.toFirExpression("No operand")
conventionCallName != null -> {
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
return generateIncrementOrDecrementBlock(
expression, argument,
callName = conventionCallName,
prefix = expression is KtPrefixExpression
) { (this as KtExpression).toFirExpression("Incorrect expression inside inc/dec") }
}
FirFunctionCallImpl(expression.toFirSourceElement()).apply {
calleeReference = FirSimpleNamedReference(
expression.operationReference.toFirSourceElement(), conventionCallName, null
)
explicitReceiver = argument.toFirExpression("No operand")
}
}
} else {
val firOperation = operationToken.toFirOperation()
FirOperatorCallImpl(expression.toFirSourceElement(), firOperation).apply {
arguments += argument.toFirExpression("No operand")
else -> {
val firOperation = operationToken.toFirOperation()
FirOperatorCallImpl(expression.toFirSourceElement(), firOperation).apply {
arguments += argument.toFirExpression("No operand")
}
}
}
}
@@ -11,13 +11,5 @@ FILE: nullability.kt
}
public? final? fun bang(arg: Int?): <implicit> {
^bang when (lval <bangbang>: <implicit> = arg#) {
==($subj$, Null(null)) -> {
throw KotlinNullPointerException#()
}
else -> {
R|<local>/<bangbang>|
}
}
^bang arg#!!
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirAnonymousFunctionImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.FirCheckNotNullCallImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirFunctionCallImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirTryExpressionImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirWhenExpressionImpl
@@ -119,4 +120,15 @@ fun FirTryExpression.copy(
this@apply.catches.addAll(this@copy.catches)
this.typeRef = resultType
this.annotations += annotations
}
fun FirCheckNotNullCall.copy(
resultType: FirTypeRef = this.typeRef,
calleeReference: FirReference = this.calleeReference,
annotations: List<FirAnnotationCall> = this.annotations
): FirCheckNotNullCallImpl = FirCheckNotNullCallImpl(source).apply {
this.calleeReference = calleeReference
this@apply.arguments.addAll(this@copy.arguments)
this.typeRef = resultType
this.annotations += annotations
}
@@ -44,7 +44,7 @@ fun Candidate.resolveArgumentExpression(
typeProvider: (FirExpression) -> FirTypeRef?
) {
return when (argument) {
is FirFunctionCall, is FirWhenExpression, is FirTryExpression -> resolveSubCallArgument(
is FirFunctionCall, is FirWhenExpression, is FirTryExpression, is FirCheckNotNullCall -> resolveSubCallArgument(
csBuilder,
argument as FirResolvable,
expectedType,
@@ -44,7 +44,7 @@ class CandidateFactory(
fun PostponedArgumentsAnalyzer.Context.addSubsystemFromExpression(statement: FirStatement) {
when (statement) {
is FirFunctionCall, is FirQualifiedAccessExpression, is FirWhenExpression, is FirTryExpression, is FirCallableReferenceAccess ->
is FirFunctionCall, is FirQualifiedAccessExpression, is FirWhenExpression, is FirTryExpression, is FirCheckNotNullCall, is FirCallableReferenceAccess ->
(statement as FirResolvable).candidate()?.let { addOtherSystem(it.system.asReadOnlyStorage()) }
is FirWrappedArgumentExpression -> addSubsystemFromExpression(statement.expression)
is FirBlock -> statement.returnExpressions().forEach { addSubsystemFromExpression(it) }
@@ -246,6 +246,11 @@ class ConstraintSystemCompleter(val components: InferenceComponents) {
catches.forEach { it.block.processAllContainingCallCandidates(processBlocks, processor) }
}
is FirCheckNotNullCall -> {
processCandidateIfApplicable(processor)
this.arguments.forEach { it.processAllContainingCallCandidates(processBlocks, processor) }
}
is FirQualifiedAccessExpression -> {
processCandidateIfApplicable(processor)
}
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.references.impl.FirResolvedNamedReferenceImpl
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
import org.jetbrains.kotlin.fir.resolve.calls.candidate
import org.jetbrains.kotlin.fir.resolve.calls.isBuiltinFunctionalType
import org.jetbrains.kotlin.fir.resolve.constructFunctionalTypeRef
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
@@ -52,7 +51,6 @@ class FirCallCompletionResultsWriterTransformer(
): CompositeTransformResult<FirStatement> {
val calleeReference =
qualifiedAccessExpression.calleeReference as? FirNamedReferenceWithCandidate ?: return qualifiedAccessExpression.compose()
calleeReference.candidate.substitutor
val candidateFir = calleeReference.candidateSymbol.phasedFir
val typeRef = (candidateFir as? FirTypedDeclaration)?.let {
@@ -276,49 +274,38 @@ class FirCallCompletionResultsWriterTransformer(
return transformElement(block, data)
}
override fun transformWhenExpression(whenExpression: FirWhenExpression, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
val calleeReference = whenExpression.calleeReference as? FirNamedReferenceWithCandidate ?: return whenExpression.compose()
// Transformations for synthetic calls generated by FirSyntheticCallGenerator
val whenExpression = whenExpression.transformChildren(this, data?.getExpectedType(whenExpression)?.toExpectedType()) as FirWhenExpression
override fun transformWhenExpression(whenExpression: FirWhenExpression, data: ExpectedArgumentType?) =
transformSyntheticCall(whenExpression, data)
val declaration = whenExpression.candidate()?.symbol?.fir as? FirMemberFunction<*> ?: return whenExpression.compose()
override fun transformTryExpression(tryExpression: FirTryExpression, data: ExpectedArgumentType?) =
transformSyntheticCall(tryExpression, data)
val subCandidate = calleeReference.candidate
override fun transformCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: ExpectedArgumentType?) =
transformSyntheticCall(checkNotNullCall, data)
private inline fun <reified D> transformSyntheticCall(
syntheticCall: D,
data: ExpectedArgumentType?
): CompositeTransformResult<FirStatement>
where D : FirResolvable, D : FirExpression {
val syntheticCall = syntheticCall.transformChildren(this, data?.getExpectedType(syntheticCall)?.toExpectedType()) as D
val calleeReference = syntheticCall.calleeReference as? FirNamedReferenceWithCandidate ?: return syntheticCall.compose()
val declaration = calleeReference.candidate.symbol.fir as? FirMemberFunction<*> ?: return syntheticCall.compose()
val typeRef = typeCalculator.tryCalculateReturnType(declaration)
syntheticCall.replaceTypeRefWithSubstituted(calleeReference, typeRef)
whenExpression.resultType = typeRef.substituteTypeRef(subCandidate)
return whenExpression.transformCalleeReference(
return (syntheticCall.transformCalleeReference(
StoreCalleeReference,
FirResolvedNamedReferenceImpl(
calleeReference.source,
calleeReference.name,
calleeReference.candidateSymbol
)
).compose()
}
override fun transformTryExpression(tryExpression: FirTryExpression, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
val calleeReference = tryExpression.calleeReference as? FirNamedReferenceWithCandidate ?: return tryExpression.compose()
val tryExpression = tryExpression.transformChildren(this, data) as FirTryExpression
val declaration = tryExpression.candidate()?.symbol?.fir as? FirMemberFunction<*> ?: return tryExpression.compose()
val subCandidate = calleeReference.candidate
val typeRef = typeCalculator.tryCalculateReturnType(declaration)
tryExpression.resultType = typeRef.substituteTypeRef(subCandidate)
return tryExpression.transformCalleeReference(
StoreCalleeReference,
FirResolvedNamedReferenceImpl(
calleeReference.source,
calleeReference.name,
calleeReference.candidateSymbol
)
).compose()
) as D).compose()
}
override fun <T> transformConstExpression(
@@ -16,10 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirTryExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.FirFunctionCallImpl
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.references.impl.FirStubReference
@@ -28,6 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
import org.jetbrains.kotlin.fir.resolve.withNullability
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.SyntheticCallableId
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
@@ -51,6 +49,7 @@ class FirSyntheticCallGenerator(
private val whenSelectFunction: FirSimpleFunctionImpl = generateSyntheticSelectFunction(SyntheticCallableId.WHEN)
private val trySelectFunction: FirSimpleFunctionImpl = generateSyntheticSelectFunction(SyntheticCallableId.TRY)
private val idFunction: FirSimpleFunctionImpl = generateSyntheticSelectFunction(SyntheticCallableId.ID)
private val checkNotNullFunction: FirSimpleFunctionImpl = generateSyntheticCheckNotNullFunction()
fun generateCalleeForWhenExpression(whenExpression: FirWhenExpression): FirWhenExpression? {
val stubReference = whenExpression.calleeReference
@@ -90,6 +89,19 @@ class FirSyntheticCallGenerator(
return tryExpression.transformCalleeReference(UpdateReference, reference)
}
fun generateCalleeForCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall): FirCheckNotNullCall? {
val stubReference = checkNotNullCall.calleeReference
if (stubReference !is FirStubReference) return null
val reference = generateCalleeReferenceWithCandidate(
checkNotNullFunction,
checkNotNullCall.arguments,
SyntheticCallableId.CHECK_NOT_NULL.callableName
) ?: return null // TODO
return checkNotNullCall.transformCalleeReference(UpdateReference, reference)
}
fun resolveCallableReferenceWithSyntheticOuterCall(
callableReferenceAccess: FirCallableReferenceAccess,
expectedTypeRef: FirTypeRef?
@@ -140,12 +152,15 @@ class FirSyntheticCallGenerator(
implicitReceiverStack = implicitReceiverStack
) { it.resultType }
private fun generateSyntheticSelectFunction(callableId: CallableId, isVararg: Boolean = true): FirSimpleFunctionImpl {
private fun generateSyntheticSelectFunction(callableId: CallableId): FirSimpleFunctionImpl {
// Synthetic function signature:
// fun <K> select(vararg values: K): K
val functionSymbol = FirSyntheticFunctionSymbol(callableId)
val typeParameterSymbol = FirTypeParameterSymbol()
val typeParameter = FirTypeParameterImpl(null, session, Name.identifier("K"), typeParameterSymbol, Variance.INVARIANT, false).apply {
addDefaultBoundIfNecessary()
}
val typeParameter =
FirTypeParameterImpl(null, session, Name.identifier("K"), typeParameterSymbol, Variance.INVARIANT, false).apply {
addDefaultBoundIfNecessary()
}
val returnType = FirResolvedTypeRefImpl(null, ConeTypeParameterTypeImpl(typeParameterSymbol.toLookupTag(), false))
@@ -154,7 +169,38 @@ class FirSyntheticCallGenerator(
return generateMemberFunction(session, functionSymbol, callableId.callableName, typeArgument.typeRef).apply {
typeParameters += typeParameter
valueParameters += argumentType.toValueParameter(session, "branches", isVararg)
valueParameters += argumentType.toValueParameter(session, "branches", isVararg = true)
}
}
private fun generateSyntheticCheckNotNullFunction(): FirSimpleFunctionImpl {
// Synthetic function signature:
// fun <K> checkNotNull(arg: K?): K
//
// Note: The upper bound of `K` cannot be `Any` because of the following case:
// fun <X> test(a: X) = a!!
// `X` is not a subtype of `Any` and hence cannot satisfy `K` if it had an upper bound of `Any`.
val functionSymbol = FirSyntheticFunctionSymbol(SyntheticCallableId.CHECK_NOT_NULL)
val typeParameterSymbol = FirTypeParameterSymbol()
val typeParameter =
FirTypeParameterImpl(null, session, Name.identifier("K"), typeParameterSymbol, Variance.INVARIANT, false).apply {
addDefaultBoundIfNecessary()
}
val returnType = FirResolvedTypeRefImpl(null, ConeTypeParameterTypeImpl(typeParameterSymbol.toLookupTag(), false))
val argumentType =
FirResolvedTypeRefImpl(null, returnType.coneTypeUnsafe<ConeKotlinType>().withNullability(ConeNullability.NULLABLE))
val typeArgument = FirTypeProjectionWithVarianceImpl(null, returnType, Variance.INVARIANT)
return generateMemberFunction(
session,
functionSymbol,
SyntheticCallableId.CHECK_NOT_NULL.callableName,
typeArgument.typeRef
).apply {
typeParameters += typeParameter
valueParameters += argumentType.toValueParameter(session, "arg")
}
}
@@ -113,6 +113,13 @@ open class FirBodyResolveTransformer(
return expressionsTransformer.transformTypeOperatorCall(typeOperatorCall, data)
}
override fun transformCheckNotNullCall(
checkNotNullCall: FirCheckNotNullCall,
data: ResolutionMode
): CompositeTransformResult<FirStatement> {
return expressionsTransformer.transformCheckNotNullCall(checkNotNullCall, data)
}
override fun transformBinaryLogicExpression(
binaryLogicExpression: FirBinaryLogicExpression,
data: ResolutionMode
@@ -287,6 +287,31 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) :
return resolved.transform(integerLiteralTypeApproximator, null)
}
override fun transformCheckNotNullCall(
checkNotNullCall: FirCheckNotNullCall,
data: ResolutionMode
): CompositeTransformResult<FirStatement> {
// Resolve the return type of a call to the synthetic function with signature:
// fun <K> checkNotNull(arg: K?): K
// ...in order to get the not-nullable type of the argument.
if (checkNotNullCall.calleeReference is FirResolvedNamedReference && checkNotNullCall.resultType !is FirImplicitTypeRef) {
return checkNotNullCall.compose()
}
checkNotNullCall.transformArguments(transformer, ResolutionMode.ContextDependent)
val result = components.syntheticCallGenerator.generateCalleeForCheckNotNullCall(checkNotNullCall)?.let {
callCompleter.completeCall(it, data.expectedType)
} ?: run {
checkNotNullCall.resultType =
FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Can't resolve !! operator call", DiagnosticKind.InferenceError))
checkNotNullCall
}
// TODO: Data flow analysis
return result.compose()
}
override fun transformBinaryLogicExpression(
binaryLogicExpression: FirBinaryLogicExpression,
data: ResolutionMode
@@ -1,4 +1,4 @@
fun <R> materialize(): R = <!UNRESOLVED_REFERENCE!>null!!<!>
fun <R> materialize(): R = null!!
fun test_1() {
<!UNRESOLVED_REFERENCE!>myRun<!> {
@@ -1,14 +1,6 @@
FILE: lambdaInUnresolvedCall.kt
public final fun <R> materialize(): R|R| {
^materialize when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|
}
}
^materialize Null(null)!!
}
public final fun test_1(): R|kotlin/Unit| {
<Unresolved name: myRun>#(<L> = myRun@fun <anonymous>(): R|kotlin/Int| {
@@ -1,4 +1,4 @@
fun <K> materialize(): K = <!UNRESOLVED_REFERENCE!>null!!<!>
fun <K> materialize(): K = null!!
open class A1(val x: String)
class B1 : A1(materialize())
@@ -1,14 +1,6 @@
FILE: delegatingConstructorCall.kt
public final fun <K> materialize(): R|K| {
^materialize when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|
}
}
^materialize Null(null)!!
}
public open class A1 : R|kotlin/Any| {
public constructor(x: R|kotlin/String|): R|A1| {
@@ -1,6 +1,6 @@
fun <T> listOf(): List<T> = <!UNRESOLVED_REFERENCE!>null!!<!>
fun <T> listOf(): List<T> = null!!
fun <T> materialize(): T = <!UNRESOLVED_REFERENCE!>null!!<!>
fun <T> materialize(): T = null!!
class Result
@@ -1,25 +1,9 @@
FILE: nestedClassNameClash.kt
public final fun <T> listOf(): R|kotlin/collections/List<T>| {
^listOf when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|
}
}
^listOf Null(null)!!
}
public final fun <T> materialize(): R|T| {
^materialize when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|
}
}
^materialize Null(null)!!
}
public final class Result : R|kotlin/Any| {
public constructor(): R|Result| {
@@ -9,28 +9,12 @@ FILE: inferenceFromCallableReferenceType.kt
}
public final fun baz(x: R|kotlin/String|): R|kotlin/Int| {
^baz when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
^baz Null(null)!!
}
}
public final fun bar(x: R|kotlin/String|): R|kotlin/Int| {
^bar when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
^bar Null(null)!!
}
public final fun main(): R|kotlin/Unit| {
R|/foo|<R|kotlin/String|, R|kotlin/Int|>(::R|/bar|)
@@ -9,28 +9,12 @@ FILE: inferenceFromExpectedType.kt
}
public final fun <T, E> baz(x: R|T|): R|E| {
^baz when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
^baz Null(null)!!
}
}
public final fun <T, E> bar(x: R|T|): R|E| {
^bar when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
^bar Null(null)!!
}
public final fun main(): R|kotlin/Unit| {
R|/foo|(::R|/bar<kotlin/String, kotlin/Int>|)
@@ -7,15 +7,7 @@ FILE: factoryFunctionOverloads.kt
}
public final fun A(b: R|B?|, flag: R|kotlin/Boolean| = Boolean(true)): R|A| {
^A R|/A.A|(when (lval <bangbang>: R|B?| = R|<local>/b|) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
, R|<local>/flag|)
^A R|/A.A|(R|<local>/b|!!, R|<local>/flag|)
}
public final fun A(c: R|C|, flag: R|kotlin/Boolean| = Boolean(true)): R|A| {
^A R|/A.A|(R|<local>/c|.R|/C.b|, R|<local>/flag|)
+1 -9
View File
@@ -18,13 +18,5 @@ FILE: hashSet.kt
public final fun foo(): R|kotlin/Unit| {
lvar c: R|kotlin/collections/MutableSet<kotlin/String>?| = Null(null)
R|<local>/c| = R|java/util/HashSet.HashSet|<R|kotlin/String|>()
when (lval <bangbang>: R|java/util/HashSet<kotlin/String>| = R|<local>/c|) {
==($subj$, Null(null)) -> {
throw R|kotlin/KotlinNullPointerException.KotlinNullPointerException|()
}
else -> {
R|<local>/<bangbang>|
}
}
.R|/d| = R|/produce|<R|T?|>()
R|<local>/c|!!.R|/d| = R|/produce|<R|T?|>()
}
+1 -1
View File
@@ -1,5 +1,5 @@
fun <T, R> T.also(block: () -> R): R {
return <!UNRESOLVED_REFERENCE!>null!!<!>
return null!!
}
fun foo(b: Boolean, a: Int) {
+1 -9
View File
@@ -1,14 +1,6 @@
FILE: whenAsReceiver.kt
public final fun <T, R> R|T|.also(block: R|() -> R|): R|R| {
^also when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|
}
}
^also Null(null)!!
}
public final fun foo(b: R|kotlin/Boolean|, a: R|kotlin/Int|): R|kotlin/Unit| {
lval x: R|kotlin/Int?| = when (R|<local>/b|) {
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2019 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.expressions
import org.jetbrains.kotlin.fir.FirPureAbstractElement
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirCheckNotNullCall : FirPureAbstractElement(), FirExpression, FirCall, FirResolvable {
abstract override val source: FirSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotationCall>
abstract override val arguments: List<FirExpression>
abstract override val calleeReference: FirReference
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitCheckNotNullCall(this, data)
abstract override fun <D> transformArguments(transformer: FirTransformer<D>, data: D): FirCheckNotNullCall
abstract override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirCheckNotNullCall
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2019 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.expressions.impl
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.references.impl.FirStubReference
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
class FirCheckNotNullCallImpl(
override val source: FirSourceElement?
) : FirCheckNotNullCall(), FirAbstractAnnotatedElement {
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override val arguments: MutableList<FirExpression> = mutableListOf()
override var calleeReference: FirReference = FirStubReference()
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
typeRef.accept(visitor, data)
annotations.forEach { it.accept(visitor, data) }
arguments.forEach { it.accept(visitor, data) }
calleeReference.accept(visitor, data)
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirCheckNotNullCallImpl {
typeRef = typeRef.transformSingle(transformer, data)
annotations.transformInplace(transformer, data)
transformArguments(transformer, data)
transformCalleeReference(transformer, data)
return this
}
override fun <D> transformArguments(transformer: FirTransformer<D>, data: D): FirCheckNotNullCallImpl {
arguments.transformInplace(transformer, data)
return this
}
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirCheckNotNullCallImpl {
calleeReference = calleeReference.transformSingle(transformer, data)
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef
}
}
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessWithoutCallee
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall
import org.jetbrains.kotlin.fir.expressions.FirArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
@@ -396,6 +397,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformElement(qualifiedAccess, data)
}
open fun transformCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: D): CompositeTransformResult<FirStatement> {
return transformElement(checkNotNullCall, data)
}
open fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): CompositeTransformResult<FirStatement> {
return transformElement(arrayOfCall, data)
}
@@ -844,6 +849,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformQualifiedAccess(qualifiedAccess, data)
}
final override fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: D): CompositeTransformResult<FirStatement> {
return transformCheckNotNullCall(checkNotNullCall, data)
}
final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): CompositeTransformResult<FirStatement> {
return transformArrayOfCall(arrayOfCall, data)
}
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessWithoutCallee
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall
import org.jetbrains.kotlin.fir.expressions.FirArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
@@ -260,6 +261,8 @@ abstract class FirVisitor<out R, in D> {
open fun visitQualifiedAccess(qualifiedAccess: FirQualifiedAccess, data: D): R = visitElement(qualifiedAccess, data)
open fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: D): R = visitElement(checkNotNullCall, data)
open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): R = visitElement(arrayOfCall, data)
open fun visitArraySetCall(arraySetCall: FirArraySetCall, data: D): R = visitElement(arraySetCall, data)
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessWithoutCallee
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall
import org.jetbrains.kotlin.fir.expressions.FirArraySetCall
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
@@ -394,6 +395,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(qualifiedAccess)
}
open fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall) {
visitElement(checkNotNullCall)
}
open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall) {
visitElement(arrayOfCall)
}
@@ -842,6 +847,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitQualifiedAccess(qualifiedAccess)
}
final override fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: Nothing?) {
visitCheckNotNullCall(checkNotNullCall)
}
final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Nothing?) {
visitArrayOfCall(arrayOfCall)
}
@@ -923,6 +923,11 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
}
}
override fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall) {
checkNotNullCall.argument.accept(this)
print("!!")
}
override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess) {
callableReferenceAccess.annotations.renderAnnotations()
callableReferenceAccess.explicitReceiver?.accept(this)
@@ -26,7 +26,7 @@ inline val FirAnnotationCall.classId: ClassId?
fun <T> FirConstExpressionImpl(source: FirSourceElement?, kind: FirConstKind<T>, value: T?, diagnostic: FirDiagnostic): FirExpression =
value?.let { FirConstExpressionImpl(source, kind, it) } ?: FirErrorExpressionImpl(source, diagnostic)
inline val FirTypeOperatorCall.argument: FirExpression get() = arguments.first()
inline val FirCall.argument: FirExpression get() = arguments.first()
fun FirExpression.toResolvedCallableReference(): FirResolvedNamedReference? {
return (this as? FirQualifiedAccess)?.calleeReference as? FirResolvedNamedReference
@@ -86,6 +86,7 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val whenBranch = element("WhenBranch", Expression)
val qualifiedAccessWithoutCallee = element("QualifiedAccessWithoutCallee", Expression, statement)
val qualifiedAccess = element("QualifiedAccess", Expression, qualifiedAccessWithoutCallee, resolvable)
val checkNotNullCall = element("CheckNotNullCall", Expression, expression, call, resolvable)
val arrayOfCall = element("ArrayOfCall", Expression, expression, call)
val arraySetCall = element("ArraySetCall", Expression, qualifiedAccess, call)
@@ -245,6 +245,11 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
defaultNoReceivers()
}
impl(checkNotNullCall) {
default("calleeReference", "FirStubReference()")
useTypes(stubReferenceType)
}
noImpl(expressionWithSmartcast)
impl(getClassCall) {