psi2ir: Fix implicit casts generation

Implicit cast from T to S is not required if
  T <: S.makeNullable()
This commit is contained in:
Dmitry Petrov
2018-05-29 15:46:16 +03:00
parent dac9036969
commit cb301763f3
7 changed files with 320 additions and 9 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.isNullabilityFlexible
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.types.upperIfFlexible
fun insertImplicitCasts(builtIns: KotlinBuiltIns, element: IrElement, symbolTable: SymbolTable) {
@@ -203,7 +204,7 @@ class InsertImplicitCasts(private val builtIns: KotlinBuiltIns, private val symb
implicitCast(nonNullValueType, IrTypeOperator.IMPLICIT_NOTNULL).cast(expectedType)
}
KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType.makeNotNullable(), expectedType) ->
KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType, expectedType.makeNullable()) ->
this
KotlinBuiltIns.isInt(valueType) && notNullableExpectedType.isBuiltInIntegerType() ->