Repository: JetBrains/kotlin
File: compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt (Kotlin)

Code before:

    override fun TypeParameterMarker.getRepresentativeUpperBound(): KotlinTypeMarker =
        (this as IrTypeParameterSymbol).owner.superTypes.firstOrNull {
            val irClass = it.classOrNull?.owner ?: return@firstOrNull false
            irClass.kind != ClassKind.INTERFACE && irClass.kind != ClassKind.ANNOTATION_CLASS
        } ?: owner.superTypes.first()

    override fun KotlinTypeMarker.getSubstitutedUnderlyingType(): KotlinTypeMarker? {
        // Code in inlineClassesUtils.kt loads the property with the same name from the scope of the substituted type and takes its type.
        // This code below should have the same effect.
        val irClass = (this as? IrType)?.classOrNull?.owner?.takeIf { it.isInline } ?: return null
        val inlineClassParameter = irClass.primaryConstructor?.valueParameters?.singleOrNull()
        return inlineClassParameter?.let { parameter ->
            // Taking only the type parameters of the class (and not its outer classes) is OK since inner classes are always top level
            IrTypeSubstitutor(
                irClass.typeParameters.map { it.symbol },
                (this as? IrSimpleType)?.arguments.orEmpty(),
                irBuiltIns
            ).substitute(parameter.type)
        }
    }

    override fun TypeConstructorMarker.getPrimitiveType(): PrimitiveType? {
        if (this !is IrClassSymbol || !isPublicApi) return null

        val signature = signature?.asPublic()
        if (signature == null || signature.packageFqName != "kotlin") return null

        return PrimitiveType.getByShortName(signature.declarationFqName)
    }

    override fun TypeConstructorMarker.getPrimitiveArrayType(): PrimitiveType? {
        if (this !is IrClassSymbol || !isPublicApi) return null

        val signature = signature?.asPublic()
        if (signature == null || signature.packageFqName != "kotlin") return null

        return PrimitiveType.getByShortArrayName(signature.declarationFqName)
    }

    override fun TypeConstructorMarker.isUnderKotlinPackage(): Boolean {
        var declaration: IrDeclaration = (this as? IrClassifierSymbol)?.owner as? IrClass ?: return false
        while (true) {
            val parent = declaration.parent
            if (parent is IrPackageFragment) {
                return parent.fqName.startsWith(StandardNames.BUILT_INS_PACKAGE_NAME)
            }
            declaration = parent as? IrDeclaration ?: return false
        }
    }


Review comment (suggestion):
The call to `isPublicApi` above is no longer needed here and in `getPrimitiveArrayType`

Code after:

    override fun TypeParameterMarker.getRepresentativeUpperBound(): KotlinTypeMarker =
        (this as IrTypeParameterSymbol).owner.superTypes.firstOrNull {
            val irClass = it.classOrNull?.owner ?: return@firstOrNull false
            irClass.kind != ClassKind.INTERFACE && irClass.kind != ClassKind.ANNOTATION_CLASS
        } ?: owner.superTypes.first()

    override fun KotlinTypeMarker.getSubstitutedUnderlyingType(): KotlinTypeMarker? {
        // Code in inlineClassesUtils.kt loads the property with the same name from the scope of the substituted type and takes its type.
        // This code below should have the same effect.
        val irClass = (this as? IrType)?.classOrNull?.owner?.takeIf { it.isInline } ?: return null
        val inlineClassParameter = irClass.primaryConstructor?.valueParameters?.singleOrNull()
        return inlineClassParameter?.let { parameter ->
            // Taking only the type parameters of the class (and not its outer classes) is OK since inner classes are always top level
            IrTypeSubstitutor(
                irClass.typeParameters.map { it.symbol },
                (this as? IrSimpleType)?.arguments.orEmpty(),
                irBuiltIns
            ).substitute(parameter.type)
        }
    }

    override fun TypeConstructorMarker.getPrimitiveType(): PrimitiveType? {
        if (this !is IrClassSymbol) return null

        val signature = signature?.asPublic()
        if (signature == null || signature.packageFqName != "kotlin") return null

        return PrimitiveType.getByShortName(signature.declarationFqName)
    }

    override fun TypeConstructorMarker.getPrimitiveArrayType(): PrimitiveType? {
        if (this !is IrClassSymbol) return null

        val signature = signature?.asPublic()
        if (signature == null || signature.packageFqName != "kotlin") return null

        return PrimitiveType.getByShortArrayName(signature.declarationFqName)
    }

    override fun TypeConstructorMarker.isUnderKotlinPackage(): Boolean {
        var declaration: IrDeclaration = (this as? IrClassifierSymbol)?.owner as? IrClass ?: return false
        while (true) {
            val parent = declaration.parent
            if (parent is IrPackageFragment) {
                return parent.fqName.startsWith(StandardNames.BUILT_INS_PACKAGE_NAME)
            }
            declaration = parent as? IrDeclaration ?: return false
        }
    }