Fix compiler warnings in compiler code
This commit is contained in:
@@ -75,8 +75,8 @@ class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
|
||||
override val allModules: Collection<M> = listOf()
|
||||
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>) = throw IllegalStateException("Should not be called for $infos")
|
||||
|
||||
override fun moduleInfoForModuleDescriptor(descriptor: ModuleDescriptor): M {
|
||||
throw IllegalStateException("$descriptor is not contained in this resolver")
|
||||
override fun moduleInfoForModuleDescriptor(moduleDescriptor: ModuleDescriptor): M {
|
||||
throw IllegalStateException("$moduleDescriptor is not contained in this resolver")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
package org.jetbrains.kotlin.checkers.diagnostics
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory1
|
||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.AbstractDiagnosticWithParametersRenderer
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticRenderer
|
||||
@@ -143,7 +141,10 @@ class TextDiagnostic(
|
||||
private fun asTextDiagnostic(actualDiagnostic: ActualDiagnostic): TextDiagnostic {
|
||||
val diagnostic = actualDiagnostic.diagnostic
|
||||
val renderer = when (diagnostic.factory) {
|
||||
is DebugInfoDiagnosticFactory1 -> DiagnosticWithParameters1Renderer("{0}", TO_STRING) as DiagnosticRenderer<Diagnostic>
|
||||
is DebugInfoDiagnosticFactory1 -> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
DiagnosticWithParameters1Renderer("{0}", TO_STRING) as DiagnosticRenderer<Diagnostic>
|
||||
}
|
||||
else -> DefaultErrorMessages.getRendererForDiagnostic(diagnostic)
|
||||
}
|
||||
val diagnosticName = actualDiagnostic.name
|
||||
|
||||
@@ -1180,6 +1180,7 @@ public interface Errors {
|
||||
initializeFactoryNamesAndDefaultErrorMessages(aClass, DiagnosticFactoryToRendererMap::new);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static void initializeFactoryNamesAndDefaultErrorMessages(
|
||||
@NotNull Class<?> aClass,
|
||||
@NotNull DefaultErrorMessages.Extension defaultErrorMessages
|
||||
@@ -1193,7 +1194,6 @@ public interface Errors {
|
||||
DiagnosticFactory<?> factory = (DiagnosticFactory<?>)value;
|
||||
factory.setName(field.getName());
|
||||
|
||||
//noinspection rawtypes, unchecked
|
||||
factory.setDefaultRenderer((DiagnosticRenderer) diagnosticToRendererMap.get(factory));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ fun getEnclosingDescriptor(context: BindingContext, element: KtElement): Declara
|
||||
getEnclosingDescriptor(context, declaration)
|
||||
} else {
|
||||
context.get(DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
?: throw KotlinExceptionWithAttachments("No descriptor for named declaration of type ${declaration?.javaClass}")
|
||||
?: throw KotlinExceptionWithAttachments("No descriptor for named declaration of type ${declaration.javaClass}")
|
||||
.withAttachment("declaration.kt", declaration.text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
||||
|
||||
if (inlinableParameters.contains(targetDescriptor)) {
|
||||
when {
|
||||
!checkNotInDefaultParameter(context, targetDescriptor, expression) -> { /*error*/
|
||||
!checkNotInDefaultParameter(context, expression) -> { /*error*/
|
||||
}
|
||||
!isInsideCall(expression) -> context.trace.report(USAGE_IS_NOT_INLINABLE.on(expression, expression, descriptor))
|
||||
}
|
||||
@@ -94,7 +94,7 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
||||
checkRecursion(context, targetDescriptor, expression)
|
||||
}
|
||||
|
||||
private fun checkNotInDefaultParameter(context: CallCheckerContext, targetDescriptor: CallableDescriptor, expression: KtExpression) =
|
||||
private fun checkNotInDefaultParameter(context: CallCheckerContext, expression: KtExpression) =
|
||||
!supportDefaultValueInline || expression.getParentOfType<KtParameter>(true)?.let {
|
||||
val allow = it !in inlinableKtParameters
|
||||
if (!allow) {
|
||||
@@ -145,7 +145,7 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
||||
|
||||
if (argumentCallee != null && inlinableParameters.contains(argumentCallee)) {
|
||||
when {
|
||||
!checkNotInDefaultParameter(context, argumentCallee, argumentExpression) -> { /*error*/
|
||||
!checkNotInDefaultParameter(context, argumentExpression) -> { /*error*/
|
||||
}
|
||||
|
||||
InlineUtil.isInline(targetDescriptor) && InlineUtil.isInlineParameter(targetParameterDescriptor) ->
|
||||
|
||||
+2
-4
@@ -24,10 +24,8 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.isError
|
||||
|
||||
class DataFlowValueFactoryImpl
|
||||
@Deprecated("Please, avoid to use that implementation explicitly. If you need DataFlowValueFactory, use injection")
|
||||
constructor(private val languageVersionSettings: LanguageVersionSettings) : DataFlowValueFactory {
|
||||
|
||||
// Please, avoid using this implementation explicitly. If you need DataFlowValueFactory, use injection.
|
||||
class DataFlowValueFactoryImpl constructor(private val languageVersionSettings: LanguageVersionSettings) : DataFlowValueFactory {
|
||||
// Receivers
|
||||
override fun createDataFlowValue(
|
||||
receiverValue: ReceiverValue,
|
||||
|
||||
+3
-3
@@ -312,10 +312,10 @@ class KotlinResolutionCallbacksImpl(
|
||||
return convertSignedConstantToUnsigned(argumentExpression)
|
||||
}
|
||||
|
||||
override fun recordInlinabilityOfLambda(lambdas: Set<Map.Entry<KotlinResolutionCandidate, ResolvedLambdaAtom>>) {
|
||||
val call = lambdas.first().value.atom.psiCallArgument.valueArgument as? KtLambdaArgument ?: return
|
||||
override fun recordInlinabilityOfLambda(atom: Set<Map.Entry<KotlinResolutionCandidate, ResolvedLambdaAtom>>) {
|
||||
val call = atom.first().value.atom.psiCallArgument.valueArgument as? KtLambdaArgument ?: return
|
||||
val literal = call.getLambdaExpression()?.functionLiteral ?: return
|
||||
val isLambdaInline = lambdas.all { (candidate, atom) ->
|
||||
val isLambdaInline = atom.all { (candidate, atom) ->
|
||||
if (!InlineUtil.isInline(candidate.resolvedCall.candidateDescriptor)) return
|
||||
val valueParameterDescriptor = candidate.resolvedCall.argumentToCandidateParameter[atom.atom] ?: return
|
||||
InlineUtil.isInlineParameter(valueParameterDescriptor)
|
||||
|
||||
+1
@@ -155,6 +155,7 @@ class KotlinToResolvedCallTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val resolvedCall = ktPrimitiveCompleter.completeResolvedCall(
|
||||
candidate, baseResolvedCall.completedDiagnostic(resultSubstitutor),
|
||||
) as ResolvedCall<D>
|
||||
|
||||
@@ -68,7 +68,6 @@ val KotlinCallArgument.psiExpression: KtExpression?
|
||||
class ParseErrorKotlinCallArgument(
|
||||
override val valueArgument: ValueArgument,
|
||||
override val dataFlowInfoAfterThisArgument: DataFlowInfo,
|
||||
builtIns: KotlinBuiltIns
|
||||
) : ExpressionKotlinCallArgument, SimplePSIKotlinCallArgument() {
|
||||
override val receiver = ReceiverValueWithSmartCastInfo(
|
||||
TransientReceiver(ErrorUtils.createErrorType("Error type for ParseError-argument $valueArgument")),
|
||||
|
||||
-2
@@ -606,10 +606,8 @@ fun transformToReceiverWithSmartCastInfo(
|
||||
)
|
||||
}
|
||||
|
||||
@Deprecated("Temporary error")
|
||||
internal class PreviousResolutionError(candidateLevel: ResolutionCandidateApplicability) : ResolutionDiagnostic(candidateLevel)
|
||||
|
||||
@Deprecated("Temporary error")
|
||||
internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResolutionError? {
|
||||
val level = when (status) {
|
||||
ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null
|
||||
|
||||
@@ -721,7 +721,7 @@ class PSICallResolver(
|
||||
): PSIKotlinCallArgument {
|
||||
val builtIns = outerCallContext.scope.ownerDescriptor.builtIns
|
||||
|
||||
fun createParseErrorElement() = ParseErrorKotlinCallArgument(valueArgument, startDataFlowInfo, builtIns)
|
||||
fun createParseErrorElement() = ParseErrorKotlinCallArgument(valueArgument, startDataFlowInfo)
|
||||
|
||||
val argumentExpression = valueArgument.getArgumentExpression() ?: return createParseErrorElement()
|
||||
val ktExpression = KtPsiUtil.deparenthesize(argumentExpression) ?: createParseErrorElement()
|
||||
|
||||
+1
@@ -202,6 +202,7 @@ class ResolvedAtomCompleter(
|
||||
}
|
||||
|
||||
private fun completeLambda(lambda: ResolvedLambdaAtom) {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val lambda = lambda.unwrap()
|
||||
val resultArgumentsInfo = lambda.resultArgumentsInfo!!
|
||||
val returnType = if (lambda.isCoercedToUnit) {
|
||||
|
||||
+2
-2
@@ -849,7 +849,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
val compileTimeConstant = evaluate(argumentExpression, underlyingType)
|
||||
val evaluatedArgument = compileTimeConstant?.toConstantValue(underlyingType) ?: return null
|
||||
|
||||
val unsignedValue = ConstantValueFactory.createUnsignedValue(evaluatedArgument, classDescriptor.defaultType) ?: return null
|
||||
val unsignedValue = ConstantValueFactory.createUnsignedValue(evaluatedArgument) ?: return null
|
||||
return unsignedValue.wrap(compileTimeConstant.parameters)
|
||||
}
|
||||
|
||||
@@ -1168,7 +1168,7 @@ private fun typeStrToCompileTimeType(str: String) = when (str) {
|
||||
else -> throw IllegalArgumentException("Unsupported type: $str")
|
||||
}
|
||||
|
||||
fun evaluateUnary(name: String, typeStr: String, value: Any, tracer: () -> Unit = {}): Any? {
|
||||
fun evaluateUnary(name: String, typeStr: String, value: Any): Any? {
|
||||
return evaluateUnaryAndCheck(name, typeStrToCompileTimeType(typeStr), value)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ import java.util.HashMap
|
||||
|
||||
/** This file is generated by org.jetbrains.kotlin.generators.evaluate:generate(). DO NOT MODIFY MANUALLY */
|
||||
|
||||
internal val emptyBinaryFun: Function2<BigInteger, BigInteger, BigInteger> = { a, b -> BigInteger("0") }
|
||||
internal val emptyUnaryFun: Function1<Long, Long> = { a -> 1.toLong() }
|
||||
internal val emptyBinaryFun: Function2<BigInteger, BigInteger, BigInteger> = { _, _ -> BigInteger("0") }
|
||||
internal val emptyUnaryFun: Function1<Long, Long> = { _ -> 1.toLong() }
|
||||
|
||||
internal val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>
|
||||
= hashMapOf<UnaryOperationKey<*>, Pair<Function1<Any?, Any>, Function1<Long, Long>>>(
|
||||
|
||||
+1
-2
@@ -37,7 +37,7 @@ class InlineAnalyzerExtension(
|
||||
|
||||
override fun process(descriptor: CallableMemberDescriptor, functionOrProperty: KtCallableDeclaration, trace: BindingTrace) {
|
||||
checkModalityAndOverrides(descriptor, functionOrProperty, trace)
|
||||
notSupportedInInlineCheck(descriptor, functionOrProperty, trace)
|
||||
notSupportedInInlineCheck(functionOrProperty, trace)
|
||||
|
||||
if (descriptor is FunctionDescriptor) {
|
||||
assert(functionOrProperty is KtNamedFunction) {
|
||||
@@ -61,7 +61,6 @@ class InlineAnalyzerExtension(
|
||||
}
|
||||
|
||||
private fun notSupportedInInlineCheck(
|
||||
descriptor: CallableMemberDescriptor,
|
||||
functionOrProperty: KtCallableDeclaration,
|
||||
trace: BindingTrace
|
||||
) {
|
||||
|
||||
-15
@@ -81,21 +81,6 @@ private fun KotlinTypeRefiner.refineBareType(type: PossiblyBareType): PossiblyBa
|
||||
return PossiblyBareType.type(newType)
|
||||
}
|
||||
|
||||
@OptIn(TypeRefinement::class)
|
||||
private fun <T : DoubleColonLHS> KotlinTypeRefiner.refineLHS(lhs: T): T = when (lhs) {
|
||||
is DoubleColonLHS.Expression -> {
|
||||
val newType = lhs.typeInfo.type?.let { refineType(it) }
|
||||
DoubleColonLHS.Expression(
|
||||
lhs.typeInfo.replaceType(newType),
|
||||
lhs.isObjectQualifier
|
||||
) as T
|
||||
}
|
||||
is DoubleColonLHS.Type -> {
|
||||
DoubleColonLHS.Type(refineType(lhs.type), refineBareType(lhs.possiblyBareType)) as T
|
||||
}
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
|
||||
// Returns true if this expression has the form "A<B>" which means it's a type on the LHS of a double colon expression
|
||||
internal val KtCallExpression.isWithoutValueArguments: Boolean
|
||||
get() = valueArgumentList == null && lambdaArguments.isEmpty()
|
||||
|
||||
+1
@@ -99,6 +99,7 @@ public class ExpressionTypingUtils {
|
||||
return fakeExpression;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void checkVariableShadowing(
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull BindingTrace trace,
|
||||
|
||||
Reference in New Issue
Block a user