All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.backend.jvm.JvmIrTypeSystemContext.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * 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.backend.jvm

import org.jetbrains.kotlin.backend.jvm.ir.IrJvmFlexibleType
import org.jetbrains.kotlin.backend.jvm.ir.asJvmFlexibleType
import org.jetbrains.kotlin.backend.jvm.ir.isWithFlexibleNullability
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
import org.jetbrains.kotlin.ir.types.isMarkedNullable as irIsMarkedNullable
import org.jetbrains.kotlin.types.model.FlexibleTypeMarker
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.SimpleTypeMarker

class JvmIrTypeSystemContext(override val irBuiltIns: IrBuiltIns) : IrTypeSystemContext {
    override fun KotlinTypeMarker.asFlexibleType(): FlexibleTypeMarker? =
        (this as IrType).asJvmFlexibleType(irBuiltIns)

    override fun FlexibleTypeMarker.upperBound(): SimpleTypeMarker {
        return when (this) {
            is IrJvmFlexibleType -> this.upperBound
            else -> error("Unexpected flexible type ${this::class.java.simpleName}: $this")
        }
    }

    override fun FlexibleTypeMarker.lowerBound(): SimpleTypeMarker {
        return when (this) {
            is IrJvmFlexibleType -> this.lowerBound
            else -> error("Unexpected flexible type ${this::class.java.simpleName}: $this")
        }
    }

    override fun KotlinTypeMarker.isMarkedNullable(): Boolean =
        this is IrSimpleType && !isWithFlexibleNullability() && irIsMarkedNullable()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy