Skip to content

Commit

Permalink
[KAPT+IR] Use ErrorType for unresolved delegate class.
Browse files Browse the repository at this point in the history
^KT-57946

(cherry picked from commit 699ad87)
  • Loading branch information
madsager authored and qodana-bot committed Apr 19, 2023
1 parent d50f585 commit c98b2a7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeProjectionImpl
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.error.ErrorUtils.createErrorType
import org.jetbrains.kotlin.utils.newHashMapWithExpectedSize

@ObsoleteDescriptorBasedAPI
Expand Down Expand Up @@ -200,7 +202,11 @@ class ClassGenerator(
delegateNumber: Int
) {
val ktDelegateExpression = ktEntry.delegateExpression!!
val delegateType = getTypeInferredByFrontendOrFail(ktDelegateExpression)
val delegateType = if (context.configuration.generateBodies) {
getTypeInferredByFrontendOrFail(ktDelegateExpression)
} else {
getTypeInferredByFrontend(ktDelegateExpression) ?: createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktDelegateExpression.text)
}
val superType = getOrFail(BindingContext.TYPE, ktEntry.typeReference!!)

val superTypeConstructorDescriptor = superType.constructor.declarationDescriptor
Expand All @@ -213,11 +219,16 @@ class ClassGenerator(
irClass.properties.first { it.descriptor == propertyDescriptor }.backingField!!
} else {
val delegateDescriptor = IrImplementingDelegateDescriptorImpl(irClass.descriptor, delegateType, superType, delegateNumber)
val initializer = if (context.configuration.generateBodies) {
createBodyGenerator(irClass.symbol).generateExpressionBody(ktDelegateExpression)
} else {
null
}
context.symbolTable.declareField(
ktDelegateExpression.startOffsetSkippingComments, ktDelegateExpression.endOffset,
IrDeclarationOrigin.DELEGATE,
delegateDescriptor, delegateDescriptor.type.toIrType(),
createBodyGenerator(irClass.symbol).generateExpressionBody(ktDelegateExpression)
initializer
).apply {
irClass.addMember(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ class B : NonExisting {
val a: String by flaf()
}

interface I

@Suppress("UNRESOLVED_REFERENCE")
class D : I by NonExisting

fun C.flaf() = "OK"

@Suppress("UNRESOLVED_REFERENCE", "DELEGATION_NOT_TO_INTERFACE")
class E : NonExisting by NonExisting
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ public class C {
////////////////////


@kotlin.Metadata()
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
public final class D implements I {

public D() {
super();
}
}

////////////////////


@kotlin.Metadata()
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE", "DELEGATION_NOT_TO_INTERFACE"})
public final class E implements NonExisting {

public E() {
super();
}
}

////////////////////


@kotlin.Metadata()
public abstract interface I {
}

////////////////////


@kotlin.Metadata()
public final class UnresolvedDelegateExpressionKt {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ public class C {
////////////////////


@kotlin.Metadata()
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
public final class D implements I {

public D() {
super();
}
}

////////////////////


@kotlin.Metadata()
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE", "DELEGATION_NOT_TO_INTERFACE"})
public final class E implements NonExisting {

public E() {
super();
}
}

////////////////////


@kotlin.Metadata()
public abstract interface I {
}

////////////////////


@kotlin.Metadata()
public final class UnresolvedDelegateExpressionKt {

Expand Down

0 comments on commit c98b2a7

Please sign in to comment.