FIR: Resolve error expression in initializer of FirField
^KT-54775 Fixed
This commit is contained in:
committed by
Space Team
parent
156c2db855
commit
583584be7e
+6
@@ -368,6 +368,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54220.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt54775.kt")
|
||||
public void testKt54775() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54775.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labelAndReceiverForInfix.kt")
|
||||
public void testLabelAndReceiverForInfix() throws Exception {
|
||||
|
||||
+5
@@ -314,6 +314,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54220.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt54775.kt")
|
||||
public void testKt54775() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54775.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("labelAndReceiverForInfix.kt")
|
||||
public void testLabelAndReceiverForInfix() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/labelAndReceiverForInfix.kt");
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
FILE: kt54775.kt
|
||||
public final fun <T> bar(): R|T| {
|
||||
^bar (Null(null) as R|T|)
|
||||
}
|
||||
public final class X : <ERROR TYPE REF: Symbol not found for B> {
|
||||
public constructor(): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
private final field $$delegate_0: <ERROR TYPE REF: Symbol not found for B> = ERROR_EXPR(Should have delegate)
|
||||
|
||||
public final val prop: <ERROR TYPE REF: Should have initializer> = ERROR_EXPR(Should have initializer)
|
||||
public get(): <ERROR TYPE REF: Should have initializer>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun <T> bar(): T {
|
||||
return null <!UNCHECKED_CAST!>as T<!>
|
||||
}
|
||||
|
||||
class X() : <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>B<!> by <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!><!VARIABLE_EXPECTED!>get()<!> = bar()<!> {
|
||||
val prop = <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!><!VARIABLE_EXPECTED!>bar()<!> = 2<!>
|
||||
}
|
||||
|
||||
+6
@@ -368,6 +368,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54220.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt54775.kt")
|
||||
public void testKt54775() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54775.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labelAndReceiverForInfix.kt")
|
||||
public void testLabelAndReceiverForInfix() throws Exception {
|
||||
|
||||
+6
@@ -368,6 +368,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54220.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt54775.kt")
|
||||
public void testKt54775() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/kt54775.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labelAndReceiverForInfix.kt")
|
||||
public void testLabelAndReceiverForInfix() throws Exception {
|
||||
|
||||
+7
-5
@@ -63,11 +63,13 @@ class ExpressionsConverter(
|
||||
get() = declarationsConverter.offset
|
||||
|
||||
inline fun <reified R : FirElement> getAsFirExpression(expression: LighterASTNode?, errorReason: String = ""): R {
|
||||
return expression?.let {
|
||||
convertExpression(it, errorReason)
|
||||
} as? R ?: buildErrorExpression(
|
||||
expression?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected)
|
||||
) as R
|
||||
val converted = expression?.let { convertExpression(it, errorReason) }
|
||||
return converted as? R
|
||||
?: buildErrorExpression(
|
||||
expression?.toFirSourceElement(),
|
||||
ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected),
|
||||
converted,
|
||||
) as R
|
||||
}
|
||||
|
||||
/***** EXPRESSIONS *****/
|
||||
|
||||
+4
-1
@@ -1011,7 +1011,10 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
|
||||
}
|
||||
|
||||
private val FirVariable.initializerResolved: Boolean
|
||||
get() = initializer?.typeRef is FirResolvedTypeRef
|
||||
get() {
|
||||
val initializer = initializer ?: return false
|
||||
return initializer.typeRef is FirResolvedTypeRef && initializer !is FirErrorExpression
|
||||
}
|
||||
|
||||
protected val FirFunction.bodyResolved: Boolean
|
||||
get() = body !is FirLazyBlock && body?.typeRef is FirResolvedTypeRef
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
@@ -87,10 +88,16 @@ fun buildErrorLoop(source: KtSourceElement?, diagnostic: ConeDiagnostic): FirErr
|
||||
}
|
||||
}
|
||||
|
||||
fun buildErrorExpression(source: KtSourceElement?, diagnostic: ConeDiagnostic): FirErrorExpression {
|
||||
fun buildErrorExpression(
|
||||
source: KtSourceElement?,
|
||||
diagnostic: ConeDiagnostic,
|
||||
element: FirElement? = null
|
||||
): FirErrorExpression {
|
||||
return buildErrorExpression {
|
||||
this.source = source
|
||||
this.diagnostic = diagnostic
|
||||
this.expression = element as? FirExpression
|
||||
this.nonExpressionElement = element.takeUnless { it is FirExpression }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user