diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java index 4789fdafc64..8559d57d4ed 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -226,6 +226,8 @@ public interface BindingContext { ReadOnlySlice DECLARATION_TO_DESCRIPTOR = Slices.sliceBuilder() .setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS).build(); + WritableSlice CALLABLE_REFERENCE = Slices.createSimpleSlice(); + WritableSlice LABEL_TARGET = Slices.sliceBuilder().build(); WritableSlice> AMBIGUOUS_LABEL_TARGET = Slices.>sliceBuilder().build(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java index 66a8275b301..d2a88eb2d61 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java @@ -24,8 +24,11 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.*; +import org.jetbrains.jet.lang.resolve.BindingTrace; +import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace; +import org.jetbrains.jet.lang.resolve.TypeResolver; import org.jetbrains.jet.lang.resolve.calls.context.CallResolutionContext; +import org.jetbrains.jet.lang.resolve.calls.context.CheckValueArgumentsMode; import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; @@ -90,6 +93,8 @@ public class ArgumentTypeResolver { } public void checkTypesWithNoCallee(@NotNull CallResolutionContext context, @NotNull ResolveArgumentsMode resolveFunctionArgumentBodies) { + if (context.checkArguments == CheckValueArgumentsMode.DISABLED) return; + for (ValueArgument valueArgument : context.call.getValueArguments()) { JetExpression argumentExpression = valueArgument.getArgumentExpression(); if (argumentExpression != null && !(argumentExpression instanceof JetFunctionLiteralExpression)) { @@ -113,6 +118,8 @@ public class ArgumentTypeResolver { } public void checkTypesForFunctionArgumentsWithNoCallee(@NotNull CallResolutionContext context) { + if (context.checkArguments == CheckValueArgumentsMode.DISABLED) return; + for (ValueArgument valueArgument : context.call.getValueArguments()) { JetExpression argumentExpression = valueArgument.getArgumentExpression(); if (argumentExpression != null && (argumentExpression instanceof JetFunctionLiteralExpression)) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java index 11f2e585a66..19287f94992 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallExpressionResolver.java @@ -189,7 +189,7 @@ public class CallExpressionResolver { } @Nullable - private ResolvedCallWithTrace getResolvedCallForFunction( + public ResolvedCallWithTrace getResolvedCallForFunction( @NotNull Call call, @NotNull JetExpression callExpression, @NotNull ResolutionContext context, @NotNull ResolveMode resolveMode, @NotNull CheckValueArgumentsMode checkArguments, @NotNull ResolutionResultsCache resolutionResultsCache, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index a357ea22044..2ebd303b539 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; @@ -32,13 +34,17 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory; import org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability; +import org.jetbrains.jet.lang.resolve.calls.context.CheckValueArgumentsMode; import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionResultsCache; import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode; +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace; +import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; +import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor; import org.jetbrains.jet.lang.resolve.constants.*; import org.jetbrains.jet.lang.resolve.constants.StringValue; import org.jetbrains.jet.lang.resolve.name.LabelName; @@ -46,17 +52,21 @@ import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; +import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lexer.JetTokens; +import org.jetbrains.jet.utils.ThrowingList; import java.util.*; import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*; +import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getStaticNestedClassesScope; import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*; @@ -564,8 +574,142 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { @Override public JetTypeInfo visitCallableReferenceExpression(JetCallableReferenceExpression expression, ExpressionTypingContext context) { - context.trace.report(UNSUPPORTED.on(expression, getClass().getCanonicalName())); - return JetTypeInfo.create(null, context.dataFlowInfo); + JetTypeReference typeReference = expression.getTypeReference(); + + JetType receiverType = + typeReference == null + ? null + : context.expressionTypingServices.getTypeResolver().resolveType(context.scope, typeReference, context.trace, false); + + JetSimpleNameExpression callableReference = expression.getCallableReference(); + if (callableReference.getReferencedName().isEmpty()) { + context.trace.report(UNRESOLVED_REFERENCE.on(callableReference, callableReference)); + JetType errorType = ErrorUtils.createErrorType("Empty callable reference"); + return DataFlowUtils.checkType(errorType, expression, context, context.dataFlowInfo); + } + + JetType result = getCallableReferenceType(expression, receiverType, context); + return DataFlowUtils.checkType(result, expression, context, context.dataFlowInfo); + } + + @Nullable + private static JetType getCallableReferenceType( + @NotNull JetCallableReferenceExpression expression, + @Nullable JetType lhsType, + @NotNull ExpressionTypingContext context + ) { + JetSimpleNameExpression reference = expression.getCallableReference(); + + boolean[] result = new boolean[1]; + FunctionDescriptor descriptor = resolveCallableReferenceTarget(lhsType, context, expression, result); + + if (!result[0]) { + context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); + } + if (descriptor == null) return null; + + ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter(); + ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject(); + if (receiverParameter != null && expectedThisObject != null) { + // TODO: report "extensions in classes" are not supported + context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); + return null; + } + + JetType receiverType = null; + if (receiverParameter != null) { + receiverType = receiverParameter.getType(); + } + else if (expectedThisObject != null) { + receiverType = expectedThisObject.getType(); + } + + //noinspection ConstantConditions + JetType type = KotlinBuiltIns.getInstance().getKFunctionType( + Collections.emptyList(), + receiverType, + DescriptorUtils.getValueParametersTypes(descriptor.getValueParameters()), + descriptor.getReturnType(), + receiverParameter != null + ); + + ExpressionAsFunctionDescriptor functionDescriptor = new ExpressionAsFunctionDescriptor( + context.scope.getContainingDeclaration(), + Name.special("") + ); + FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, type, null, Modality.FINAL, Visibilities.PUBLIC); + + context.trace.record(CALLABLE_REFERENCE, expression, functionDescriptor); + + return type; + } + + @Nullable + private static FunctionDescriptor resolveCallableReferenceTarget( + @Nullable JetType lhsType, + @NotNull ExpressionTypingContext context, + @NotNull JetCallableReferenceExpression expression, + @NotNull boolean[] result + ) { + JetSimpleNameExpression reference = expression.getCallableReference(); + + if (lhsType == null) { + return resolveCallableNotCheckingArguments(reference, NO_RECEIVER, context, result); + } + + ClassifierDescriptor classifier = lhsType.getConstructor().getDeclarationDescriptor(); + // TODO: report an error if the classifier is not a class + assert classifier instanceof ClassDescriptor : "TODO"; + + ReceiverValue receiver = new TransientReceiver(lhsType); + TemporaryBindingTrace traceWithReceiver = TemporaryBindingTrace.create(context.trace, + "trace to resolve callable reference with receiver", reference); + FunctionDescriptor descriptor = + resolveCallableNotCheckingArguments(reference, receiver, context.replaceBindingTrace(traceWithReceiver), result); + if (result[0]) { + traceWithReceiver.commit(); + return descriptor; + } + + JetScope staticScope = getStaticNestedClassesScope((ClassDescriptor) classifier); + TemporaryBindingTrace traceForStatic = TemporaryBindingTrace.create(context.trace, + "trace to resolve callable reference in static scope", reference); + FunctionDescriptor possibleStaticNestedClassConstructor = resolveCallableNotCheckingArguments(reference, NO_RECEIVER, + context.replaceBindingTrace(traceForStatic).replaceScope(staticScope), result); + if (result[0]) { + traceForStatic.commit(); + return possibleStaticNestedClassConstructor; + } + + return null; + } + + @Nullable + private static FunctionDescriptor resolveCallableNotCheckingArguments( + @NotNull JetSimpleNameExpression reference, + @NotNull ReceiverValue receiver, + @NotNull ExpressionTypingContext context, + @NotNull boolean[] result + ) { + Call call = CallMaker.makeCall(reference, receiver, null, reference, ThrowingList.instance()); + + TemporaryBindingTrace trace = TemporaryBindingTrace.create(context.trace, "trace to resolve as function", reference); + + ExpressionTypingContext contextForResolve = context.replaceBindingTrace(trace).replaceExpectedType(NO_EXPECTED_TYPE); + ResolvedCallWithTrace function = contextForResolve.expressionTypingServices.getCallExpressionResolver() + .getResolvedCallForFunction(call, reference, contextForResolve, ResolveMode.TOP_LEVEL_CALL, + CheckValueArgumentsMode.DISABLED, ResolutionResultsCache.create(), result); + if (!result[0]) return null; + + if (function instanceof VariableAsFunctionResolvedCall) { + // TODO: KProperty + context.trace.report(UNSUPPORTED.on(reference, "References to variables aren't supported yet")); + context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); + return null; + } + + trace.commit(); + return function != null ? function.getResultingDescriptor() : null; } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index be4c362a079..2a82cfb938a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -792,6 +792,57 @@ public class KotlinBuiltIns { @Nullable JetType receiverType, @NotNull List parameterTypes, @NotNull JetType returnType + ) { + List arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType); + int size = parameterTypes.size(); + ClassDescriptor classDescriptor = receiverType == null ? getFunction(size) : getExtensionFunction(size); + TypeConstructor constructor = classDescriptor.getTypeConstructor(); + + return new JetTypeImpl(annotations, constructor, false, arguments, classDescriptor.getMemberScope(arguments)); + } + + @NotNull + public JetType getKFunctionType( + @NotNull List annotations, + @Nullable JetType receiverType, + @NotNull List parameterTypes, + @NotNull JetType returnType, + boolean extensionFunction + ) { + List arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType); + ClassDescriptor classDescriptor = getCorrespondingKFunctionClass(receiverType, extensionFunction, parameterTypes.size()); + + return new JetTypeImpl( + annotations, + classDescriptor.getTypeConstructor(), + false, + arguments, + classDescriptor.getMemberScope(arguments) + ); + } + + @NotNull + private ClassDescriptor getCorrespondingKFunctionClass( + @Nullable JetType receiverType, + boolean extensionFunction, + int numberOfParameters + ) { + if (receiverType == null) { + return getKFunction(numberOfParameters); + } + else if (extensionFunction) { + return getKExtensionFunction(numberOfParameters); + } + else { + return getKMemberFunction(numberOfParameters); + } + } + + @NotNull + private static List getFunctionTypeArgumentProjections( + @Nullable JetType receiverType, + @NotNull List parameterTypes, + @NotNull JetType returnType ) { List arguments = new ArrayList(); if (receiverType != null) { @@ -801,10 +852,7 @@ public class KotlinBuiltIns { arguments.add(defaultProjection(parameterType)); } arguments.add(defaultProjection(returnType)); - int size = parameterTypes.size(); - ClassDescriptor classDescriptor = receiverType == null ? getFunction(size) : getExtensionFunction(size); - TypeConstructor constructor = classDescriptor.getTypeConstructor(); - return new JetTypeImpl(annotations, constructor, false, arguments, classDescriptor.getMemberScope(arguments)); + return arguments; } private static TypeProjection defaultProjection(JetType returnType) { @@ -841,17 +889,29 @@ public class KotlinBuiltIns { } public boolean isFunctionType(@NotNull JetType type) { - return setContainsClassOf(functionClassesSet, type); + if (setContainsClassOf(functionClassesSet, type)) return true; + + for (JetType superType : type.getConstructor().getSupertypes()) { + if (isFunctionType(superType)) return true; + } + + return false; } public boolean isExtensionFunctionType(@NotNull JetType type) { - return setContainsClassOf(extensionFunctionClassesSet, type); + if (setContainsClassOf(extensionFunctionClassesSet, type)) return true; + + for (JetType superType : type.getConstructor().getSupertypes()) { + if (isExtensionFunctionType(superType)) return true; + } + + return false; } @Nullable public JetType getReceiverType(@NotNull JetType type) { assert isFunctionOrExtensionFunctionType(type) : type; - if (setContainsClassOf(extensionFunctionClassesSet, type)) { + if (isExtensionFunctionType(type)) { return type.getArguments().get(0).getType(); } return null; @@ -883,7 +943,7 @@ public class KotlinBuiltIns { public List getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) { assert isFunctionOrExtensionFunctionType(type); List arguments = type.getArguments(); - int first = setContainsClassOf(extensionFunctionClassesSet, type) ? 1 : 0; + int first = isExtensionFunctionType(type) ? 1 : 0; int last = arguments.size() - 2; List parameterTypes = Lists.newArrayList(); for (int i = first; i <= last; i++) { diff --git a/compiler/testData/diagnostics/tests/callableReference/abstractClassConstructors.kt b/compiler/testData/diagnostics/tests/callableReference/abstractClassConstructors.kt new file mode 100644 index 00000000000..ffb028d4da8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/abstractClassConstructors.kt @@ -0,0 +1,11 @@ +trait A +abstract class B +annotation class C +enum class D + +fun main() { + ::A + ::B + ::C // KT-3465 + ::D +} diff --git a/compiler/testData/diagnostics/tests/callableReference/ambiguityTopLevelVsTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/ambiguityTopLevelVsTopLevel.kt new file mode 100644 index 00000000000..1a6172619bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/ambiguityTopLevelVsTopLevel.kt @@ -0,0 +1,8 @@ +fun foo(x: Int, y: Any) = x +fun foo(x: Any, y: Int) = y + +fun main() { + ::foo + + ::foo : (Int, Any) -> Unit +} diff --git a/compiler/testData/diagnostics/tests/callableReference/constructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/constructorFromClass.kt new file mode 100644 index 00000000000..11bb1bd83fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/constructorFromClass.kt @@ -0,0 +1,15 @@ +class A { + fun main() { + val x = ::A + + x : KFunction0 + } +} + +class SomeOtherClass { + fun main() { + val x = ::A + + x : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/constructorFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/constructorFromExtension.kt new file mode 100644 index 00000000000..c23a053d56d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/constructorFromExtension.kt @@ -0,0 +1,10 @@ +class A +class B + +fun A.ext() { + val x = ::A + val y = ::B + + x : KFunction0 + y : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/constructorFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/constructorFromExtensionInClass.kt new file mode 100644 index 00000000000..fa6faa6831e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/constructorFromExtensionInClass.kt @@ -0,0 +1,19 @@ +class A + +class B { + fun A.ext() { + val x = ::A + val y = ::B + + x : KFunction0 + y : KFunction0 + } + + fun B.ext() { + val x = ::A + val y = ::B + + x : KFunction0 + y : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/constructorFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/constructorFromTopLevel.kt new file mode 100644 index 00000000000..e1df8095685 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/constructorFromTopLevel.kt @@ -0,0 +1,7 @@ +class A + +fun main() { + val x = ::A + + x : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/differentPackageClass.kt b/compiler/testData/diagnostics/tests/callableReference/differentPackageClass.kt new file mode 100644 index 00000000000..025c7684eea --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/differentPackageClass.kt @@ -0,0 +1,25 @@ +// FILE: a.kt + +package first + +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +// FILE: b.kt + +package other + +import first.A + +fun main() { + val x = first.A::foo + val y = first.A::bar + val z = A::baz + + x : KMemberFunction0 + y : KMemberFunction1 + z : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/differentPackageExtension.kt b/compiler/testData/diagnostics/tests/callableReference/differentPackageExtension.kt new file mode 100644 index 00000000000..1e7843a21a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/differentPackageExtension.kt @@ -0,0 +1,24 @@ +// FILE: a.kt + +package first + +class A + +fun A.foo() {} +fun A.bar() {} +fun A.baz() {} + +// FILE: b.kt + +package other + +import first.A +import first.foo + +fun main() { + val x = first.A::foo + first.A::bar + A::baz + + x : KExtensionFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/differentPackageTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/differentPackageTopLevel.kt new file mode 100644 index 00000000000..b00730fd8d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/differentPackageTopLevel.kt @@ -0,0 +1,25 @@ +// FILE: a.kt + +package first + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +// FILE: b.kt + +package other + +import first.foo +import first.bar +import first.baz + +fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/empty.kt b/compiler/testData/diagnostics/tests/callableReference/empty.kt new file mode 100644 index 00000000000..243660cb419 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/empty.kt @@ -0,0 +1,6 @@ +class A + +fun main() { + val x = :: ; + val y = A:: +} diff --git a/compiler/testData/diagnostics/tests/callableReference/extensionFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/extensionFromClass.kt new file mode 100644 index 00000000000..1d0677bd72b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/extensionFromClass.kt @@ -0,0 +1,15 @@ +class A { + fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KExtensionFunction0 + y : KExtensionFunction1 + z : KExtensionFunction0 + } +} + +fun A.foo() {} +fun A.bar(x: Int) {} +fun A.baz() = "OK" diff --git a/compiler/testData/diagnostics/tests/callableReference/extensionFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/extensionFromExtension.kt new file mode 100644 index 00000000000..36ded52ce56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/extensionFromExtension.kt @@ -0,0 +1,15 @@ +class A + +fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KExtensionFunction0 + y : KExtensionFunction1 + z : KExtensionFunction0 +} + +fun A.foo() {} +fun A.bar(x: Int) {} +fun A.baz() = "OK" diff --git a/compiler/testData/diagnostics/tests/callableReference/extensionFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/extensionFromExtensionInClass.kt new file mode 100644 index 00000000000..6140d60cfa3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/extensionFromExtensionInClass.kt @@ -0,0 +1,17 @@ +class B + +class A { + fun B.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KExtensionFunction0 + y : KExtensionFunction1 + z : KExtensionFunction0 + } +} + +fun A.foo() {} +fun A.bar(x: Int) {} +fun A.baz() = "OK" diff --git a/compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt new file mode 100644 index 00000000000..ce3c841e007 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt @@ -0,0 +1,15 @@ +class A + +fun A.foo() {} +fun A.bar(x: Int) {} +fun A.baz() = "OK" + +fun main() { + val x = A::foo + val y = A::bar + val z = A::baz + + x : KExtensionFunction0 + y : KExtensionFunction1 + z : KExtensionFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt new file mode 100644 index 00000000000..3486f124379 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt @@ -0,0 +1,9 @@ +class A(val t: T) { + fun foo(): T = t +} + +fun bar() { + val x = A::foo + + x : KMemberFunction0, String> +} diff --git a/compiler/testData/diagnostics/tests/callableReference/importedInnerConstructor.kt b/compiler/testData/diagnostics/tests/callableReference/importedInnerConstructor.kt new file mode 100644 index 00000000000..a7d431a21e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/importedInnerConstructor.kt @@ -0,0 +1,9 @@ +import A.Inner + +class A { + inner class Inner +} + +fun main() { + ::Inner +} diff --git a/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromClass.kt new file mode 100644 index 00000000000..680ed70cb43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromClass.kt @@ -0,0 +1,29 @@ +class A { + inner class Inner + + fun main() { + val x = ::Inner + val y = A::Inner + + x : KMemberFunction0 + y : KMemberFunction0 + } + + class object { + fun main() { + ::Inner + val y = A::Inner + + y : KMemberFunction0 + } + } +} + +class B { + fun main() { + ::Inner + val y = A::Inner + + y : KMemberFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromExtension.kt new file mode 100644 index 00000000000..41425e238cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromExtension.kt @@ -0,0 +1,18 @@ +class A { + inner class Inner +} + +fun A.main() { + val x = ::Inner + val y = A::Inner + + x : KMemberFunction0 + y : KMemberFunction0 +} + +fun Int.main() { + ::Inner + val y = A::Inner + + y : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromTopLevel.kt new file mode 100644 index 00000000000..578e4af8c80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/innerConstructorFromTopLevel.kt @@ -0,0 +1,10 @@ +class A { + inner class Inner +} + +fun main() { + ::Inner + val y = A::Inner + + y : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localConstructor.kt b/compiler/testData/diagnostics/tests/callableReference/localConstructor.kt new file mode 100644 index 00000000000..17b77ce4c47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localConstructor.kt @@ -0,0 +1,6 @@ +fun main() { + class A + + val x = ::A + x : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localConstructorFromExtensionInLocalClass.kt b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromExtensionInLocalClass.kt new file mode 100644 index 00000000000..51b7e12ce2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromExtensionInLocalClass.kt @@ -0,0 +1,14 @@ +fun main() { + class A + + class B { + fun Int.foo() { + val x = ::A + x : KFunction0 + } + fun A.foo() { + val x = ::A + x : KFunction0 + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalClass.kt b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalClass.kt new file mode 100644 index 00000000000..9b9803bf138 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalClass.kt @@ -0,0 +1,8 @@ +fun main() { + class A + + class B { + val x = ::A + val f: KFunction0 = x + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalExtension.kt b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalExtension.kt new file mode 100644 index 00000000000..8265c3f8b34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalExtension.kt @@ -0,0 +1,13 @@ +fun main() { + class A + + fun A.foo() { + val x = ::A + x : KFunction0 + } + + fun Int.foo() { + val x = ::A + x : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localNamedFun.kt b/compiler/testData/diagnostics/tests/callableReference/localNamedFun.kt new file mode 100644 index 00000000000..635d0f5dad0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localNamedFun.kt @@ -0,0 +1,13 @@ +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromExtensionInLocalClass.kt b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromExtensionInLocalClass.kt new file mode 100644 index 00000000000..c9667d03acc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromExtensionInLocalClass.kt @@ -0,0 +1,19 @@ +class A + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + class B { + fun A.ext() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalClass.kt b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalClass.kt new file mode 100644 index 00000000000..75887872fee --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalClass.kt @@ -0,0 +1,17 @@ +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + class A { + val x = ::foo + val y = ::bar + val z = ::baz + + fun main() { + x : KFunction0 + y : KFunction1 + z : KFunction0 + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalExtension.kt b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalExtension.kt new file mode 100644 index 00000000000..e98cf12bdb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalExtension.kt @@ -0,0 +1,17 @@ +class A + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + fun A.ext() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/longQualifiedName.kt b/compiler/testData/diagnostics/tests/callableReference/longQualifiedName.kt new file mode 100644 index 00000000000..58aec0eb4db --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/longQualifiedName.kt @@ -0,0 +1,15 @@ +// FILE: a.kt + +package a.b.c + +class D { + fun foo() = 42 +} + +// FILE: b.kt + +fun main() { + val x = a.b.c.D::foo + + x : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/longQualifiedNameGeneric.kt b/compiler/testData/diagnostics/tests/callableReference/longQualifiedNameGeneric.kt new file mode 100644 index 00000000000..78b70bd0dbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/longQualifiedNameGeneric.kt @@ -0,0 +1,15 @@ +// FILE: a.kt + +package a.b.c + +class D { + fun foo(e: E, f: F) = this +} + +// FILE: b.kt + +fun main() { + val x = a.b.c.D::foo + + x : KMemberFunction2, String, Int, a.b.c.D> +} diff --git a/compiler/testData/diagnostics/tests/callableReference/memberFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/memberFromClass.kt new file mode 100644 index 00000000000..1cf9d13122f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/memberFromClass.kt @@ -0,0 +1,15 @@ +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KMemberFunction0 + y : KMemberFunction1 + z : KMemberFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/memberFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/memberFromExtension.kt new file mode 100644 index 00000000000..4b49761e193 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/memberFromExtension.kt @@ -0,0 +1,15 @@ +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KMemberFunction0 + y : KMemberFunction1 + z : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/memberFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/memberFromExtensionInClass.kt new file mode 100644 index 00000000000..8dc01bad473 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/memberFromExtensionInClass.kt @@ -0,0 +1,17 @@ +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +class B { + fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KMemberFunction0 + y : KMemberFunction1 + z : KMemberFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/memberFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/memberFromTopLevel.kt new file mode 100644 index 00000000000..a54d91d3d42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/memberFromTopLevel.kt @@ -0,0 +1,15 @@ +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +fun main() { + val x = A::foo + val y = A::bar + val z = A::baz + + x : KMemberFunction0 + y : KMemberFunction1 + z : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromClass.kt new file mode 100644 index 00000000000..325393a0b2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromClass.kt @@ -0,0 +1,29 @@ +class A { + class Nested + + fun main() { + val x = ::Nested + val y = A::Nested + + x : KFunction0 + y : KFunction0 + } + + class object { + fun main() { + ::Nested // KT-3261 + val y = A::Nested + + y : KFunction0 + } + } +} + +class B { + fun main() { + ::Nested + val y = A::Nested + + y : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromExtension.kt new file mode 100644 index 00000000000..c874250ee53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromExtension.kt @@ -0,0 +1,17 @@ +class A { + class Nested +} + +fun A.main() { + ::Nested + val y = A::Nested + + y : KFunction0 +} + +fun Int.main() { + ::Nested + val y = A::Nested + + y : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromTopLevel.kt new file mode 100644 index 00000000000..9bf36c2d77a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromTopLevel.kt @@ -0,0 +1,9 @@ +class A { + class Nested +} + +fun main() { + val x = A::Nested + + x : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/noAmbiguityLocalVsTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityLocalVsTopLevel.kt new file mode 100644 index 00000000000..a94e4f406b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityLocalVsTopLevel.kt @@ -0,0 +1,7 @@ +fun bar() = 42 + +fun main() { + fun bar() = 239 + + ::bar +} diff --git a/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsExtension.kt b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsExtension.kt new file mode 100644 index 00000000000..273da3b2b73 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsExtension.kt @@ -0,0 +1,11 @@ +class A { + fun foo() = 42 +} + +fun A.foo() {} + +fun main() { + val x = A::foo + + x : KMemberFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsTopLevel.kt new file mode 100644 index 00000000000..bb33818fe4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsTopLevel.kt @@ -0,0 +1,11 @@ +fun foo() {} + +class A { + fun foo() {} + + fun main() { + val x = ::foo + + x : KMemberFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/renameOnImport.kt b/compiler/testData/diagnostics/tests/callableReference/renameOnImport.kt new file mode 100644 index 00000000000..1dae56d6c7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/renameOnImport.kt @@ -0,0 +1,27 @@ +// FILE: a.kt + +package other + +fun foo() {} + +class A { + fun bar() = 42 +} + +fun A.baz(x: String) {} + +// FILE: b.kt + +import other.foo as foofoo +import other.A as AA +import other.baz as bazbaz + +fun main() { + val x = ::foofoo + val y = AA::bar + val z = AA::bazbaz + + x : KFunction0 + y : KMemberFunction0 + z : KExtensionFunction1 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/topLevelFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/topLevelFromClass.kt new file mode 100644 index 00000000000..7c3660f0ce3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/topLevelFromClass.kt @@ -0,0 +1,15 @@ +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +class A { + fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtension.kt new file mode 100644 index 00000000000..f18c7b46a44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtension.kt @@ -0,0 +1,15 @@ +class A + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtensionInClass.kt new file mode 100644 index 00000000000..bffbab043f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/topLevelFromExtensionInClass.kt @@ -0,0 +1,17 @@ +class A + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +class B { + fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/topLevelFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/topLevelFromTopLevel.kt new file mode 100644 index 00000000000..fc7d114c8bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/topLevelFromTopLevel.kt @@ -0,0 +1,13 @@ +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + x : KFunction0 + y : KFunction1 + z : KFunction0 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/unresolved.kt b/compiler/testData/diagnostics/tests/callableReference/unresolved.kt new file mode 100644 index 00000000000..7f25900280f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unresolved.kt @@ -0,0 +1,11 @@ +class A + +fun main() { + val foo = ::foo + + ::bar + + A::bar + + B::bar +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 2a09f55db89..713b647ed1b 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -33,7 +33,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve; @InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class}) public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve { @TestMetadata("compiler/testData/diagnostics/tests") - @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Varargs.class}) + @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.CallableReference.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Varargs.class}) public static class Tests extends AbstractDiagnosticsTestWithEagerResolve { @TestMetadata("Abstract.kt") public void testAbstract() throws Exception { @@ -705,6 +705,239 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage } + @TestMetadata("compiler/testData/diagnostics/tests/callableReference") + public static class CallableReference extends AbstractDiagnosticsTestWithEagerResolve { + @TestMetadata("abstractClassConstructors.kt") + public void testAbstractClassConstructors() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/abstractClassConstructors.kt"); + } + + public void testAllFilesPresentInCallableReference() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/callableReference"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("ambiguityTopLevelVsTopLevel.kt") + public void testAmbiguityTopLevelVsTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/ambiguityTopLevelVsTopLevel.kt"); + } + + @TestMetadata("constructorFromClass.kt") + public void testConstructorFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/constructorFromClass.kt"); + } + + @TestMetadata("constructorFromExtension.kt") + public void testConstructorFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/constructorFromExtension.kt"); + } + + @TestMetadata("constructorFromExtensionInClass.kt") + public void testConstructorFromExtensionInClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/constructorFromExtensionInClass.kt"); + } + + @TestMetadata("constructorFromTopLevel.kt") + public void testConstructorFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/constructorFromTopLevel.kt"); + } + + @TestMetadata("differentPackageClass.kt") + public void testDifferentPackageClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/differentPackageClass.kt"); + } + + @TestMetadata("differentPackageExtension.kt") + public void testDifferentPackageExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/differentPackageExtension.kt"); + } + + @TestMetadata("differentPackageTopLevel.kt") + public void testDifferentPackageTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/differentPackageTopLevel.kt"); + } + + @TestMetadata("empty.kt") + public void testEmpty() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/empty.kt"); + } + + @TestMetadata("extensionFromClass.kt") + public void testExtensionFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromClass.kt"); + } + + @TestMetadata("extensionFromExtension.kt") + public void testExtensionFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromExtension.kt"); + } + + @TestMetadata("extensionFromExtensionInClass.kt") + public void testExtensionFromExtensionInClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromExtensionInClass.kt"); + } + + @TestMetadata("extensionFromTopLevel.kt") + public void testExtensionFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt"); + } + + @TestMetadata("genericClassFromTopLevel.kt") + public void testGenericClassFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt"); + } + + @TestMetadata("importedInnerConstructor.kt") + public void testImportedInnerConstructor() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/importedInnerConstructor.kt"); + } + + @TestMetadata("innerConstructorFromClass.kt") + public void testInnerConstructorFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/innerConstructorFromClass.kt"); + } + + @TestMetadata("innerConstructorFromExtension.kt") + public void testInnerConstructorFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/innerConstructorFromExtension.kt"); + } + + @TestMetadata("innerConstructorFromTopLevel.kt") + public void testInnerConstructorFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/innerConstructorFromTopLevel.kt"); + } + + @TestMetadata("localConstructor.kt") + public void testLocalConstructor() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localConstructor.kt"); + } + + @TestMetadata("localConstructorFromExtensionInLocalClass.kt") + public void testLocalConstructorFromExtensionInLocalClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localConstructorFromExtensionInLocalClass.kt"); + } + + @TestMetadata("localConstructorFromLocalClass.kt") + public void testLocalConstructorFromLocalClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalClass.kt"); + } + + @TestMetadata("localConstructorFromLocalExtension.kt") + public void testLocalConstructorFromLocalExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localConstructorFromLocalExtension.kt"); + } + + @TestMetadata("localNamedFun.kt") + public void testLocalNamedFun() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localNamedFun.kt"); + } + + @TestMetadata("localNamedFunFromExtensionInLocalClass.kt") + public void testLocalNamedFunFromExtensionInLocalClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localNamedFunFromExtensionInLocalClass.kt"); + } + + @TestMetadata("localNamedFunFromLocalClass.kt") + public void testLocalNamedFunFromLocalClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalClass.kt"); + } + + @TestMetadata("localNamedFunFromLocalExtension.kt") + public void testLocalNamedFunFromLocalExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/localNamedFunFromLocalExtension.kt"); + } + + @TestMetadata("longQualifiedName.kt") + public void testLongQualifiedName() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/longQualifiedName.kt"); + } + + @TestMetadata("longQualifiedNameGeneric.kt") + public void testLongQualifiedNameGeneric() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/longQualifiedNameGeneric.kt"); + } + + @TestMetadata("memberFromClass.kt") + public void testMemberFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/memberFromClass.kt"); + } + + @TestMetadata("memberFromExtension.kt") + public void testMemberFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/memberFromExtension.kt"); + } + + @TestMetadata("memberFromExtensionInClass.kt") + public void testMemberFromExtensionInClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/memberFromExtensionInClass.kt"); + } + + @TestMetadata("memberFromTopLevel.kt") + public void testMemberFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/memberFromTopLevel.kt"); + } + + @TestMetadata("nestedConstructorFromClass.kt") + public void testNestedConstructorFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromClass.kt"); + } + + @TestMetadata("nestedConstructorFromExtension.kt") + public void testNestedConstructorFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromExtension.kt"); + } + + @TestMetadata("nestedConstructorFromTopLevel.kt") + public void testNestedConstructorFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/nestedConstructorFromTopLevel.kt"); + } + + @TestMetadata("noAmbiguityLocalVsTopLevel.kt") + public void testNoAmbiguityLocalVsTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityLocalVsTopLevel.kt"); + } + + @TestMetadata("noAmbiguityMemberVsExtension.kt") + public void testNoAmbiguityMemberVsExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsExtension.kt"); + } + + @TestMetadata("noAmbiguityMemberVsTopLevel.kt") + public void testNoAmbiguityMemberVsTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityMemberVsTopLevel.kt"); + } + + @TestMetadata("renameOnImport.kt") + public void testRenameOnImport() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/renameOnImport.kt"); + } + + @TestMetadata("topLevelFromClass.kt") + public void testTopLevelFromClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/topLevelFromClass.kt"); + } + + @TestMetadata("topLevelFromExtension.kt") + public void testTopLevelFromExtension() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/topLevelFromExtension.kt"); + } + + @TestMetadata("topLevelFromExtensionInClass.kt") + public void testTopLevelFromExtensionInClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/topLevelFromExtensionInClass.kt"); + } + + @TestMetadata("topLevelFromTopLevel.kt") + public void testTopLevelFromTopLevel() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/topLevelFromTopLevel.kt"); + } + + @TestMetadata("unresolved.kt") + public void testUnresolved() throws Exception { + doTest("compiler/testData/diagnostics/tests/callableReference/unresolved.kt"); + } + + } + @TestMetadata("compiler/testData/diagnostics/tests/cast") public static class Cast extends AbstractDiagnosticsTestWithEagerResolve { public void testAllFilesPresentInCast() throws Exception { @@ -4500,6 +4733,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage suite.addTestSuite(Tests.class); suite.addTestSuite(Annotations.class); suite.addTestSuite(BackingField.class); + suite.addTestSuite(CallableReference.class); suite.addTestSuite(Cast.class); suite.addTestSuite(CheckArguments.class); suite.addTestSuite(ControlFlowAnalysis.class); diff --git a/compiler/util/src/org/jetbrains/jet/utils/ThrowingList.java b/compiler/util/src/org/jetbrains/jet/utils/ThrowingList.java new file mode 100644 index 00000000000..8405ddc9ec2 --- /dev/null +++ b/compiler/util/src/org/jetbrains/jet/utils/ThrowingList.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2013 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.jet.utils; + +import org.jetbrains.annotations.NotNull; + +import java.util.AbstractList; + +public class ThrowingList extends AbstractList { + private static final ThrowingList INSTANCE = new ThrowingList(); + + private ThrowingList() {} + + @NotNull + public static ThrowingList instance() { + //noinspection unchecked + return (ThrowingList) INSTANCE; + } + + @Override + public E get(int index) { + throw new UnsupportedOperationException(getClass().getName()); + } + + @Override + public int size() { + throw new UnsupportedOperationException(getClass().getName()); + } +}