[FIR] Complete delegated constructor calls without proper constructed type

This is needed to definitely complete arguments of such calls
This commit is contained in:
Dmitriy Novozhilov
2022-02-04 15:28:02 +03:00
committed by teamcity
parent 1591518cf6
commit aadfc59d0f
10 changed files with 62 additions and 19 deletions
@@ -0,0 +1,3 @@
KtErrorCallInfo:
candidateCalls = []
diagnostic = ERROR<UNRESOLVED_REFERENCE: Unresolved reference: Unresolved>
@@ -1,3 +1,3 @@
KtErrorCallInfo:
candidateCalls = []
diagnostic = ERROR<UNRESOLVED_REFERENCE: Unresolved reference: Unresolved>
diagnostic = ERROR<OTHER_ERROR: Unknown (other) error>
@@ -1175,6 +1175,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("erroneousDelegatedConstructorCall.kt")
public void testErroneousDelegatedConstructorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/constructors/erroneousDelegatedConstructorCall.kt");
}
@Test
@TestMetadata("noSuperCallInSupertypes.kt")
public void testNoSuperCallInSupertypes() throws Exception {
@@ -1019,6 +1019,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("erroneousDelegatedConstructorCall.kt")
public void testErroneousDelegatedConstructorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/constructors/erroneousDelegatedConstructorCall.kt");
}
@TestMetadata("noSuperCallInSupertypes.kt")
public void testNoSuperCallInSupertypes() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/constructors/noSuperCallInSupertypes.kt");
@@ -0,0 +1,7 @@
FILE: erroneousDelegatedConstructorCall.kt
public final class A : <ERROR TYPE REF: Symbol not found for Undefined> {
public constructor(): R|A| {
super<<ERROR TYPE REF: Symbol not found for Undefined>>(R|/id|<R|ERROR CLASS: Cannot infer argument for type parameter K|>(R|/materialize|<R|ERROR CLASS: Cannot infer argument for type parameter K|>()))
}
}
@@ -0,0 +1,2 @@
// INFERENCE_HELPERS
class A : <!UNRESOLVED_REFERENCE!>Undefined<!>(id(materialize()))
@@ -1175,6 +1175,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("erroneousDelegatedConstructorCall.kt")
public void testErroneousDelegatedConstructorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/constructors/erroneousDelegatedConstructorCall.kt");
}
@Test
@TestMetadata("noSuperCallInSupertypes.kt")
public void testNoSuperCallInSupertypes() throws Exception {
@@ -1175,6 +1175,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("erroneousDelegatedConstructorCall.kt")
public void testErroneousDelegatedConstructorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/constructors/erroneousDelegatedConstructorCall.kt");
}
@Test
@TestMetadata("noSuperCallInSupertypes.kt")
public void testNoSuperCallInSupertypes() throws Exception {
@@ -12,7 +12,9 @@ import org.jetbrains.kotlin.fir.declarations.utils.hasExplicitBackingField
import org.jetbrains.kotlin.fir.declarations.utils.isInner
import org.jetbrains.kotlin.fir.declarations.utils.isReferredViaField
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedReifiedParameterReference
import org.jetbrains.kotlin.fir.references.*
@@ -436,15 +438,14 @@ class FirCallResolver(
fun resolveDelegatingConstructorCall(
delegatedConstructorCall: FirDelegatedConstructorCall,
constructedType: ConeClassLikeType
constructedType: ConeClassLikeType?
): FirDelegatedConstructorCall {
val name = SpecialNames.INIT
val symbol = constructedType.lookupTag.toSymbol(components.session)
val typeArguments =
constructedType.typeArguments.take((symbol?.fir as? FirRegularClass)?.typeParameters?.count { it is FirTypeParameter } ?: 0)
.map {
it.toFirTypeProjection()
}
val symbol = constructedType?.lookupTag?.toSymbol(components.session)
val typeArguments = constructedType?.typeArguments
?.take((symbol?.fir as? FirRegularClass)?.typeParameters?.count { it is FirTypeParameter } ?: 0)
?.map { it.toFirTypeProjection() }
?: emptyList()
val callInfo = CallInfo(
delegatedConstructorCall,
@@ -460,6 +461,17 @@ class FirCallResolver(
)
towerResolver.reset()
if (constructedType == null) {
val errorReference = createErrorReferenceWithErrorCandidate(
callInfo,
ConeSimpleDiagnostic("Erroneous delegated constructor call", DiagnosticKind.UnresolvedSupertype),
delegatedConstructorCall.calleeReference.source,
transformer.resolutionContext,
components.resolutionStageRunner
)
return delegatedConstructorCall.transformCalleeReference(StoreNameReference, errorReference)
}
val result = towerResolver.runResolverForDelegatingConstructor(
callInfo,
constructedType,
@@ -1057,17 +1057,13 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
}
val reference = delegatedConstructorCall.calleeReference
val constructorType: ConeClassLikeType = when (reference) {
is FirThisReference -> {
lastDispatchReceiver?.type as? ConeClassLikeType ?: return delegatedConstructorCall
}
is FirSuperReference -> {
// TODO: unresolved supertype
val supertype = reference.superTypeRef.coneTypeSafe<ConeClassLikeType>()
?.takeIf { it !is ConeErrorType } ?: return delegatedConstructorCall
supertype.fullyExpandedType(session)
}
else -> return delegatedConstructorCall
val constructorType: ConeClassLikeType? = when (reference) {
is FirThisReference -> lastDispatchReceiver?.type as? ConeClassLikeType
is FirSuperReference -> reference.superTypeRef
.coneTypeSafe<ConeClassLikeType>()
?.takeIf { it !is ConeErrorType }
?.fullyExpandedType(session)
else -> null
}
val resolvedCall = callResolver.resolveDelegatingConstructorCall(delegatedConstructorCall, constructorType)