[FIR] Typing for try-catch
This commit is contained in:
committed by
Mikhail Glukhikh
parent
30e097a1e0
commit
b469eb293b
+16
@@ -484,6 +484,22 @@ open class FirBodyResolveTransformer(val session: FirSession, val implicitTypeOn
|
||||
return functionCall
|
||||
}
|
||||
|
||||
override fun transformTryExpression(tryExpression: FirTryExpression, data: Any?): CompositeTransformResult<FirStatement> {
|
||||
val tryExpression = tryExpression.transformChildren(this, data) as FirTryExpression
|
||||
if (tryExpression.resultType !is FirResolvedTypeRef) {
|
||||
val type = commonSuperType((listOf(tryExpression.tryBlock) + tryExpression.catches.map { it.block }).mapNotNull {
|
||||
val expression = it.statements.lastOrNull() as? FirExpression
|
||||
if (expression != null) {
|
||||
(expression.resultType as? FirResolvedTypeRef) ?: FirErrorTypeRefImpl(session, null, "No type for when branch result")
|
||||
} else {
|
||||
FirImplicitUnitTypeRef(session, null)
|
||||
}
|
||||
})
|
||||
if (type != null) tryExpression.resultType = type
|
||||
}
|
||||
return tryExpression.compose()
|
||||
}
|
||||
|
||||
override fun transformFunctionCall(functionCall: FirFunctionCall, data: Any?): CompositeTransformResult<FirStatement> {
|
||||
if (functionCall.calleeReference !is FirSimpleNamedReference) return functionCall.compose()
|
||||
val expectedTypeRef = data as FirTypeRef?
|
||||
|
||||
+5
-6
@@ -1,15 +1,14 @@
|
||||
FILE fqName:<root> fileName:/catchParameterInTopLevelProperty.kt
|
||||
PROPERTY name:test visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final,static]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Unit visibility:public [final,static]
|
||||
EXPRESSION_BODY
|
||||
TRY type=IrErrorType
|
||||
TRY type=kotlin.Unit
|
||||
try: BLOCK type=kotlin.Unit origin=null
|
||||
CATCH parameter=val e: kotlin.Throwable [val] declared in <root>.test
|
||||
VAR name:e type:kotlin.Throwable [val]
|
||||
BLOCK type=kotlin.Unit origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:IrErrorType
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test> (): IrErrorType declared in <root>'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final,static] ' type=IrErrorType origin=null
|
||||
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Unit declared in <root>'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Unit visibility:public [final,static] ' type=kotlin.Unit origin=null
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
FILE fqName:<root> fileName:/catchParameterAccess.kt
|
||||
FUN name:test visibility:public modality:FINAL <> (f:kotlin.Function0<kotlin.Unit>) returnType:IrErrorType
|
||||
FUN name:test visibility:public modality:FINAL <> (f:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Nothing?
|
||||
VALUE_PARAMETER name:f index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test (f: kotlin.Function0<kotlin.Unit>): IrErrorType declared in <root>'
|
||||
TRY type=IrErrorType
|
||||
RETURN type=kotlin.Nothing from='public final fun test (f: kotlin.Function0<kotlin.Unit>): kotlin.Nothing? declared in <root>'
|
||||
TRY type=kotlin.Nothing?
|
||||
try: ERROR_CALL 'Unresolved reference: <Unresolved name: f>#' type=IrErrorType
|
||||
CATCH parameter=val e: java.lang.Exception [val] declared in <root>.test
|
||||
VAR name:e type:java.lang.Exception [val]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FILE fqName:<root> fileName:/tryCatch.kt
|
||||
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
TRY type=IrErrorType
|
||||
TRY type=kotlin.Unit
|
||||
try: CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null
|
||||
CATCH parameter=val e: kotlin.Throwable [val] declared in <root>.test1
|
||||
VAR name:e type:kotlin.Throwable [val]
|
||||
@@ -10,7 +10,7 @@ FILE fqName:<root> fileName:/tryCatch.kt
|
||||
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Int declared in <root>'
|
||||
TRY type=IrErrorType
|
||||
TRY type=kotlin.Int
|
||||
try: BLOCK type=kotlin.Int origin=null
|
||||
CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null
|
||||
CONST Int type=kotlin.Int value=42
|
||||
|
||||
@@ -9,7 +9,7 @@ FILE fqName:<root> fileName:/tryCatchWithImplicitCast.kt
|
||||
then: RETURN type=kotlin.Nothing from='public final fun testImplicitCast (a: kotlin.Any): kotlin.Unit declared in <root>'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
VAR name:t type:kotlin.String [val]
|
||||
TRY type=IrErrorType
|
||||
TRY type=kotlin.String
|
||||
try: GET_VAR 'a: kotlin.Any declared in <root>.testImplicitCast' type=kotlin.Any origin=null
|
||||
CATCH parameter=val e: kotlin.Throwable [val] declared in <root>.testImplicitCast
|
||||
VAR name:e type:kotlin.Throwable [val]
|
||||
|
||||
Reference in New Issue
Block a user