Extract FunctionPlaceholders from ErrorUtils to a separate component since they are not really an error
This commit is contained in:
+6
-7
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.Constrain
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.derivedFrom
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.ErrorUtils.FunctionPlaceholderTypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
@@ -269,7 +268,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
return true
|
||||
}
|
||||
|
||||
if (type == null || (type.isError() && !ErrorUtils.isFunctionPlaceholder(type))) {
|
||||
if (type == null || (type.isError() && !type.isFunctionPlaceholder)) {
|
||||
errors.add(ErrorInConstrainingType(constraintPosition))
|
||||
return true
|
||||
}
|
||||
@@ -287,13 +286,13 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
if (isErrorOrSpecialType(subType, constraintPosition) || isErrorOrSpecialType(superType, constraintPosition)) return
|
||||
if (subType == null || superType == null) return
|
||||
|
||||
assert(!ErrorUtils.isFunctionPlaceholder(superType)) {
|
||||
assert(!superType.isFunctionPlaceholder) {
|
||||
"The type for " + constraintPosition + " shouldn't be a placeholder for function type"
|
||||
}
|
||||
|
||||
// function literal { x -> ... } goes without declaring receiver type
|
||||
// and can be considered as extension function if one is expected
|
||||
val newSubType = if (constraintKind == SUB_TYPE && ErrorUtils.isFunctionPlaceholder(subType)) {
|
||||
val newSubType = if (constraintKind == SUB_TYPE && subType.isFunctionPlaceholder) {
|
||||
if (isMyTypeVariable(superType)) {
|
||||
// the constraint binds type parameter and a function type,
|
||||
// we don't add it without knowing whether it's a function type or an extension function type
|
||||
@@ -503,12 +502,12 @@ fun createTypeForFunctionPlaceholder(
|
||||
functionPlaceholder: JetType,
|
||||
expectedType: JetType
|
||||
): JetType {
|
||||
if (!ErrorUtils.isFunctionPlaceholder(functionPlaceholder)) return functionPlaceholder
|
||||
if (!functionPlaceholder.isFunctionPlaceholder) return functionPlaceholder
|
||||
|
||||
val functionPlaceholderTypeConstructor = functionPlaceholder.getConstructor() as FunctionPlaceholderTypeConstructor
|
||||
|
||||
val isExtension = KotlinBuiltIns.isExtensionFunctionType(expectedType)
|
||||
val newArgumentTypes = if (!functionPlaceholderTypeConstructor.hasDeclaredArguments()) {
|
||||
val newArgumentTypes = if (!functionPlaceholderTypeConstructor.hasDeclaredArguments) {
|
||||
val typeParamSize = expectedType.getConstructor().getParameters().size()
|
||||
// the first parameter is receiver (if present), the last one is return type,
|
||||
// the remaining are function arguments
|
||||
@@ -518,7 +517,7 @@ fun createTypeForFunctionPlaceholder(
|
||||
result
|
||||
}
|
||||
else {
|
||||
functionPlaceholderTypeConstructor.getArgumentTypes()
|
||||
functionPlaceholderTypeConstructor.argumentTypes
|
||||
}
|
||||
val receiverType = if (isExtension) DONT_CARE else null
|
||||
return functionPlaceholder.builtIns.getFunctionType(Annotations.EMPTY, receiverType, newArgumentTypes, DONT_CARE)
|
||||
|
||||
@@ -513,7 +513,12 @@ public class ErrorUtils {
|
||||
|
||||
@NotNull
|
||||
public static JetType createErrorTypeWithCustomDebugName(@NotNull String debugName) {
|
||||
return new ErrorTypeImpl(createErrorTypeConstructorWithCustomDebugName(debugName), createErrorScope(debugName));
|
||||
return createErrorTypeWithCustomConstructor(debugName, createErrorTypeConstructorWithCustomDebugName(debugName));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType createErrorTypeWithCustomConstructor(@NotNull String debugName, @NotNull TypeConstructor typeConstructor) {
|
||||
return new ErrorTypeImpl(typeConstructor, createErrorScope(debugName));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -527,7 +532,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static TypeConstructor createErrorTypeConstructorWithCustomDebugName(@NotNull String debugName) {
|
||||
public static TypeConstructor createErrorTypeConstructorWithCustomDebugName(@NotNull String debugName) {
|
||||
return createErrorTypeConstructorWithCustomDebugName(debugName, ERROR_CLASS);
|
||||
}
|
||||
|
||||
@@ -709,9 +714,8 @@ public class ErrorUtils {
|
||||
|
||||
@NotNull
|
||||
public static JetType createUninferredParameterType(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||
return new ErrorTypeImpl(
|
||||
new UninferredParameterTypeConstructor(typeParameterDescriptor),
|
||||
createErrorScope("Scope for error type for not inferred parameter: " + typeParameterDescriptor.getName()));
|
||||
return createErrorTypeWithCustomConstructor("Scope for error type for not inferred parameter: " + typeParameterDescriptor.getName(),
|
||||
new UninferredParameterTypeConstructor(typeParameterDescriptor));
|
||||
}
|
||||
|
||||
public static class UninferredParameterTypeConstructor implements TypeConstructor {
|
||||
@@ -769,82 +773,5 @@ public class ErrorUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFunctionPlaceholder(@Nullable JetType type) {
|
||||
return type != null && type.getConstructor() instanceof FunctionPlaceholderTypeConstructor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType createFunctionPlaceholderType(@NotNull List<JetType> argumentTypes, boolean hasDeclaredArguments) {
|
||||
return new ErrorTypeImpl(
|
||||
new FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments),
|
||||
createErrorScope("Scope for function placeholder type"));
|
||||
}
|
||||
|
||||
public static class FunctionPlaceholderTypeConstructor implements TypeConstructor {
|
||||
private final TypeConstructor errorTypeConstructor;
|
||||
private final List<JetType> argumentTypes;
|
||||
private final boolean hasDeclaredArguments;
|
||||
|
||||
private FunctionPlaceholderTypeConstructor(@NotNull List<JetType> argumentTypes, boolean hasDeclaredArguments) {
|
||||
errorTypeConstructor = createErrorTypeConstructorWithCustomDebugName("PLACEHOLDER_FUNCTION_TYPE" + argumentTypes);
|
||||
this.argumentTypes = argumentTypes;
|
||||
this.hasDeclaredArguments = hasDeclaredArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetType> getArgumentTypes() {
|
||||
return argumentTypes;
|
||||
}
|
||||
|
||||
public boolean hasDeclaredArguments() {
|
||||
return hasDeclaredArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return errorTypeConstructor.getParameters();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return errorTypeConstructor.getSupertypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return errorTypeConstructor.isFinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return errorTypeConstructor.isDenotable();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return errorTypeConstructor.getDeclarationDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
return errorTypeConstructor.getAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return errorTypeConstructor.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinBuiltIns getBuiltIns() {
|
||||
return errorTypeConstructor.getBuiltIns();
|
||||
}
|
||||
}
|
||||
|
||||
private ErrorUtils() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
|
||||
class FunctionPlaceholders(private val builtIns: KotlinBuiltIns) {
|
||||
fun createFunctionPlaceholderType(
|
||||
argumentTypes: List<JetType>,
|
||||
hasDeclaredArguments: Boolean
|
||||
): JetType {
|
||||
return ErrorUtils.createErrorTypeWithCustomConstructor(
|
||||
"function placeholder type",
|
||||
FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments, builtIns)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val JetType?.isFunctionPlaceholder: Boolean
|
||||
get() {
|
||||
return this != null && constructor is FunctionPlaceholderTypeConstructor
|
||||
}
|
||||
|
||||
class FunctionPlaceholderTypeConstructor(
|
||||
val argumentTypes: List<JetType>,
|
||||
val hasDeclaredArguments: Boolean,
|
||||
private val kotlinBuiltIns: KotlinBuiltIns
|
||||
) : TypeConstructor {
|
||||
private val errorTypeConstructor: TypeConstructor = ErrorUtils.createErrorTypeConstructorWithCustomDebugName("PLACEHOLDER_FUNCTION_TYPE" + argumentTypes)
|
||||
|
||||
override fun getParameters(): List<TypeParameterDescriptor> {
|
||||
return errorTypeConstructor.parameters
|
||||
}
|
||||
|
||||
override fun getSupertypes(): Collection<JetType> {
|
||||
return errorTypeConstructor.supertypes
|
||||
}
|
||||
|
||||
override fun isFinal(): Boolean {
|
||||
return errorTypeConstructor.isFinal
|
||||
}
|
||||
|
||||
override fun isDenotable(): Boolean {
|
||||
return errorTypeConstructor.isDenotable
|
||||
}
|
||||
|
||||
override fun getDeclarationDescriptor(): ClassifierDescriptor? {
|
||||
return errorTypeConstructor.declarationDescriptor
|
||||
}
|
||||
|
||||
override fun getAnnotations(): Annotations {
|
||||
return errorTypeConstructor.annotations
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return errorTypeConstructor.toString()
|
||||
}
|
||||
|
||||
override fun getBuiltIns(): KotlinBuiltIns {
|
||||
return kotlinBuiltIns
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user