Fix IR generation for '!is' pattern
This commit is contained in:
+12
-2
@@ -205,12 +205,22 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta
|
||||
val typeOperand = getOrFail(BindingContext.TYPE, ktCondition.typeReference)
|
||||
val irTypeOperand = typeOperand.toIrType()
|
||||
val typeSymbol = irTypeOperand.classifierOrNull ?: throw AssertionError("Not a classifier type: $typeOperand")
|
||||
return IrTypeOperatorCallImpl(
|
||||
val irInstanceOf = IrTypeOperatorCallImpl(
|
||||
ktCondition.startOffset, ktCondition.endOffset,
|
||||
context.irBuiltIns.booleanType,
|
||||
IrTypeOperator.INSTANCEOF, irTypeOperand, typeSymbol,
|
||||
IrTypeOperator.INSTANCEOF,
|
||||
irTypeOperand, typeSymbol,
|
||||
irSubject.defaultLoad()
|
||||
)
|
||||
return if (ktCondition.isNegated)
|
||||
IrUnaryPrimitiveImpl(
|
||||
ktCondition.startOffset, ktCondition.endOffset,
|
||||
context.irBuiltIns.booleanType,
|
||||
IrStatementOrigin.EXCL, context.irBuiltIns.booleanNotSymbol,
|
||||
irInstanceOf
|
||||
)
|
||||
else
|
||||
irInstanceOf
|
||||
}
|
||||
|
||||
private fun generateInRangeCondition(irSubject: IrVariable, ktCondition: KtWhenConditionInRange): IrExpression {
|
||||
|
||||
+4
-3
@@ -75,9 +75,10 @@ FILE fqName:<root> fileName:/whenByFloatingPoint.kt
|
||||
GET_VAR 'value-parameter x: Any' type=kotlin.Any origin=null
|
||||
WHEN type=kotlin.Int origin=WHEN
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Double
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Double modality:FINAL visibility:public flags: superTypes:[kotlin.Number; kotlin.Comparable<kotlin.Double>; java.io.Serializable]
|
||||
GET_VAR 'tmp0_subject: Any' type=kotlin.Any origin=null
|
||||
if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCL
|
||||
arg0: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Double
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Double modality:FINAL visibility:public flags: superTypes:[kotlin.Number; kotlin.Comparable<kotlin.Double>; java.io.Serializable]
|
||||
GET_VAR 'tmp0_subject: Any' type=kotlin.Any origin=null
|
||||
then: CONST Int type=kotlin.Int value=-1
|
||||
BRANCH
|
||||
if: CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
|
||||
|
||||
@@ -7,6 +7,7 @@ fun testWithSubject(x: Any?) =
|
||||
null -> "null"
|
||||
A -> "A"
|
||||
is String -> "String"
|
||||
!is Number -> "!Number"
|
||||
in setOf<Nothing>() -> "nothingness?"
|
||||
else -> "something"
|
||||
}
|
||||
@@ -16,6 +17,7 @@ fun test(x: Any?) =
|
||||
x == null -> "null"
|
||||
x == A -> "A"
|
||||
x is String -> "String"
|
||||
x !is Number -> "!Number"
|
||||
x in setOf<Nothing>() -> "nothingness?"
|
||||
else -> "something"
|
||||
}
|
||||
|
||||
+21
-6
@@ -42,11 +42,19 @@ FILE fqName:<root> fileName:/when.kt
|
||||
GET_VAR 'tmp0_subject: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=String
|
||||
BRANCH
|
||||
if: CALL 'contains(Any) on Iterable<Any>: Boolean' type=kotlin.Boolean origin=IN
|
||||
<T>: kotlin.Any
|
||||
if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCL
|
||||
arg0: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Number
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Number modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any; java.io.Serializable]
|
||||
GET_VAR 'tmp0_subject: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=!Number
|
||||
BRANCH
|
||||
if: CALL 'contains(Number) on Iterable<Number>: Boolean' type=kotlin.Boolean origin=IN
|
||||
<T>: kotlin.Number
|
||||
$receiver: CALL 'setOf(): Set<Nothing>' type=kotlin.collections.Set<kotlin.Nothing> origin=null
|
||||
<T>: kotlin.Nothing
|
||||
element: GET_VAR 'tmp0_subject: Any?' type=kotlin.Any? origin=null
|
||||
element: TYPE_OP type=kotlin.Number origin=IMPLICIT_CAST typeOperand=kotlin.Number
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Number modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any; java.io.Serializable]
|
||||
GET_VAR 'tmp0_subject: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=nothingness?
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
@@ -72,11 +80,18 @@ FILE fqName:<root> fileName:/when.kt
|
||||
GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=String
|
||||
BRANCH
|
||||
if: CALL 'contains(Any) on Iterable<Any>: Boolean' type=kotlin.Boolean origin=IN
|
||||
<T>: kotlin.Any
|
||||
if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=kotlin.Number
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Number modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any; java.io.Serializable]
|
||||
GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=!Number
|
||||
BRANCH
|
||||
if: CALL 'contains(Number) on Iterable<Number>: Boolean' type=kotlin.Boolean origin=IN
|
||||
<T>: kotlin.Number
|
||||
$receiver: CALL 'setOf(): Set<Nothing>' type=kotlin.collections.Set<kotlin.Nothing> origin=null
|
||||
<T>: kotlin.Nothing
|
||||
element: GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null
|
||||
element: TYPE_OP type=kotlin.Number origin=IMPLICIT_CAST typeOperand=kotlin.Number
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Number modality:ABSTRACT visibility:public flags: superTypes:[kotlin.Any; java.io.Serializable]
|
||||
GET_VAR 'value-parameter x: Any?' type=kotlin.Any? origin=null
|
||||
then: CONST String type=kotlin.String value=nothingness?
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
|
||||
@@ -24,9 +24,10 @@ FILE fqName:<root> fileName:/whenWithSubjectVariable.kt
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:String modality:FINAL visibility:public flags: superTypes:[kotlin.Comparable<kotlin.String>; kotlin.CharSequence; java.io.Serializable]
|
||||
GET_VAR 'y: Any' type=kotlin.Any origin=null
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Int
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Int modality:FINAL visibility:public flags: superTypes:[kotlin.Number; kotlin.Comparable<kotlin.Int>; java.io.Serializable]
|
||||
GET_VAR 'y: Any' type=kotlin.Any origin=null
|
||||
if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCL
|
||||
arg0: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Int
|
||||
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Int modality:FINAL visibility:public flags: superTypes:[kotlin.Number; kotlin.Comparable<kotlin.Int>; java.io.Serializable]
|
||||
GET_VAR 'y: Any' type=kotlin.Any origin=null
|
||||
then: CONST Int type=kotlin.Int value=2
|
||||
BRANCH
|
||||
if: CALL 'contains(Int): Boolean' type=kotlin.Boolean origin=IN
|
||||
|
||||
Reference in New Issue
Block a user