[FIR] Move ReturnTypeCalculator to :fir:providers module

Also make it an abstract class and turn ReturnTypeCalculatorForFullBodyResolve
  into object (because it has no state and there is no need to create
  different instances of it)
This commit is contained in:
Dmitriy Novozhilov
2022-03-15 11:06:08 +03:00
committed by teamcity
parent ff1e2c05bf
commit effa3f197a
6 changed files with 9 additions and 10 deletions
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.resolve.transformers
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
interface ReturnTypeCalculator {
fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef
fun tryCalculateReturnType(symbol: FirCallableSymbol<*>): FirResolvedTypeRef {
return tryCalculateReturnType(symbol.fir)
}
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.resolve.transformers
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
class ReturnTypeCalculatorForFullBodyResolve : ReturnTypeCalculator {
override fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef {
val returnTypeRef = declaration.returnTypeRef
if (returnTypeRef is FirResolvedTypeRef) return returnTypeRef
if (declaration.origin.fromSupertypes) {
return FakeOverrideTypeCalculator.Forced.computeReturnType(declaration)
}
return buildErrorTypeRef {
diagnostic = ConeSimpleDiagnostic(
"Cannot calculate return type during full-body resolution (local class/object?): ${declaration.render()}",
DiagnosticKind.InferenceError
)
}
}
}