Search in sources :

Example 1 with TypeReconstructionResult

use of org.jetbrains.kotlin.types.TypeReconstructionResult in project kotlin by JetBrains.

the class TypeReconstructionUtil method reconstructBareType.

@NotNull
public static KotlinType reconstructBareType(@NotNull KtTypeReference right, @NotNull PossiblyBareType possiblyBareTarget, @Nullable KotlinType subjectType, @NotNull BindingTrace trace, @NotNull KotlinBuiltIns builtIns) {
    if (subjectType == null) {
        // Recovery: let's reconstruct as if we were casting from Any, to get some type there
        subjectType = builtIns.getAnyType();
    }
    TypeReconstructionResult reconstructionResult = possiblyBareTarget.reconstruct(subjectType);
    if (!reconstructionResult.isAllArgumentsInferred()) {
        TypeConstructor typeConstructor = possiblyBareTarget.getBareTypeConstructor();
        trace.report(NO_TYPE_ARGUMENTS_ON_RHS.on(right, typeConstructor.getParameters().size(), allStarProjectionsString(typeConstructor)));
    }
    KotlinType targetType = reconstructionResult.getResultingType();
    if (targetType != null) {
        if (possiblyBareTarget.isBare()) {
            trace.record(BindingContext.TYPE, right, targetType);
        }
        return targetType;
    }
    return ErrorUtils.createErrorType("Failed to reconstruct type: " + right.getText());
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) TypeReconstructionResult(org.jetbrains.kotlin.types.TypeReconstructionResult) TypeConstructor(org.jetbrains.kotlin.types.TypeConstructor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 TypeConstructor (org.jetbrains.kotlin.types.TypeConstructor)1 TypeReconstructionResult (org.jetbrains.kotlin.types.TypeReconstructionResult)1