diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index d9927b4584c..b955a1e277c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -66,6 +66,8 @@ public interface Errors { DiagnosticFactory1> UNSUPPORTED_FEATURE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 EXCEPTION_FROM_ANALYZER = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 MISSING_STDLIB = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1> EXPERIMENTAL_FEATURE_WARNING = DiagnosticFactory1.create(WARNING); DiagnosticFactory1> EXPERIMENTAL_FEATURE_ERROR = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 0e87d83f9ed..fb0b0a49128 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -156,7 +156,7 @@ public class DefaultErrorMessages { MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "''@{0}:'' annotations could be applied only to mutable properties", TO_STRING); MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_DELEGATE, "'@delegate:' annotations could be applied only to delegated properties"); MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_BACKING_FIELD, "'@field:' annotations could be applied only to properties with backing fields"); - MAP.put(INAPPLICABLE_RECEIVER_TARGET, "'@receiver:' annotations could be applied only to extension function or extension property declarations"); + MAP.put(INAPPLICABLE_RECEIVER_TARGET, "'@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations"); MAP.put(INAPPLICABLE_PARAM_TARGET, "'@param:' annotations could be applied only to primary constructor parameters"); MAP.put(REDUNDANT_ANNOTATION_TARGET, "Redundant annotation target ''{0}''", STRING); @@ -578,6 +578,7 @@ public class DefaultErrorMessages { MAP.put(EXPERIMENTAL_FEATURE_ERROR, "{0}", new LanguageFeatureMessageRenderer(LanguageFeatureMessageRenderer.Type.ERROR)); MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); + MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING); MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE); MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here"); MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/CollectionLiteralResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/CollectionLiteralResolver.kt index 8cdd7dbe9dc..20a4c91e102 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/CollectionLiteralResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/CollectionLiteralResolver.kt @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.PrimitiveType import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor -import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED -import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED_FEATURE +import org.jetbrains.kotlin.diagnostics.Errors.* import org.jetbrains.kotlin.incremental.KotlinLookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtAnnotationEntry @@ -39,43 +39,47 @@ import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo -object CollectionLiteralResolver { - val PRIMITIVE_TYPE_TO_ARRAY: Map = hashMapOf( - PrimitiveType.BOOLEAN to Name.identifier("booleanArrayOf"), - PrimitiveType.CHAR to Name.identifier("charArrayOf"), - PrimitiveType.INT to Name.identifier("intArrayOf"), - PrimitiveType.BYTE to Name.identifier("byteArrayOf"), - PrimitiveType.SHORT to Name.identifier("shortArrayOf"), - PrimitiveType.FLOAT to Name.identifier("floatArrayOf"), - PrimitiveType.LONG to Name.identifier("longArrayOf"), - PrimitiveType.DOUBLE to Name.identifier("doubleArrayOf") - ) +class CollectionLiteralResolver(val module: ModuleDescriptor, val callResolver: CallResolver, val languageVersionSettings: LanguageVersionSettings) { + companion object { + val PRIMITIVE_TYPE_TO_ARRAY: Map = hashMapOf( + PrimitiveType.BOOLEAN to Name.identifier("booleanArrayOf"), + PrimitiveType.CHAR to Name.identifier("charArrayOf"), + PrimitiveType.INT to Name.identifier("intArrayOf"), + PrimitiveType.BYTE to Name.identifier("byteArrayOf"), + PrimitiveType.SHORT to Name.identifier("shortArrayOf"), + PrimitiveType.FLOAT to Name.identifier("floatArrayOf"), + PrimitiveType.LONG to Name.identifier("longArrayOf"), + PrimitiveType.DOUBLE to Name.identifier("doubleArrayOf") + ) - val ARRAY_OF_FUNCTION = Name.identifier("arrayOf") + val ARRAY_OF_FUNCTION = Name.identifier("arrayOf") + } - fun resolveCollectionLiteral(collectionLiteralExpression: KtCollectionLiteralExpression, - context: ExpressionTypingContext, - callResolver: CallResolver, - builtIns: KotlinBuiltIns, - languageVersionSettings: LanguageVersionSettings + fun resolveCollectionLiteral( + collectionLiteralExpression: KtCollectionLiteralExpression, + context: ExpressionTypingContext ): KotlinTypeInfo { if (!isInsideAnnotationEntryOrClass(collectionLiteralExpression)) { context.trace.report(UNSUPPORTED.on(collectionLiteralExpression, "Collection literals outside of annotations")) } - checkSupportsArrayLiterals(collectionLiteralExpression, context, languageVersionSettings) + checkSupportsArrayLiterals(collectionLiteralExpression, context) - return resolveCollectionLiteralSpecialMethod(collectionLiteralExpression, context, callResolver, builtIns) + return resolveCollectionLiteralSpecialMethod(collectionLiteralExpression, context) } private fun resolveCollectionLiteralSpecialMethod( expression: KtCollectionLiteralExpression, - context: ExpressionTypingContext, - callResolver: CallResolver, - builtIns: KotlinBuiltIns + context: ExpressionTypingContext ): KotlinTypeInfo { val call = CallMaker.makeCallForCollectionLiteral(expression) - val functionDescriptor = getFunctionDescriptorForCollectionLiteral(expression, context, builtIns) + val callName = getArrayFunctionCallName(context.expectedType) + val functionDescriptor = getFunctionDescriptorForCollectionLiteral(expression, callName) + if (functionDescriptor == null) { + context.trace.report(MISSING_STDLIB.on( + expression, "Collection literal call '$callName()' is unresolved")) + return noTypeInfo(context) + } val resolutionResults = callResolver.resolveCollectionLiteralCallWithGivenDescriptor(context, expression, call, functionDescriptor) @@ -90,17 +94,13 @@ object CollectionLiteralResolver { private fun getFunctionDescriptorForCollectionLiteral( expression: KtCollectionLiteralExpression, - context: ExpressionTypingContext, - builtIns: KotlinBuiltIns - ): SimpleFunctionDescriptor { - val callName = getArrayFunctionCallName(context.expectedType) - return builtIns.builtInsPackageScope.getContributedFunctions(callName, KotlinLookupLocation(expression)).single() + callName: Name + ): SimpleFunctionDescriptor? { + val memberScopeOfKotlinPackage = module.getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME).memberScope + return memberScopeOfKotlinPackage.getContributedFunctions(callName, KotlinLookupLocation(expression)).singleOrNull() } - private fun checkSupportsArrayLiterals(expression: KtCollectionLiteralExpression, - context: ExpressionTypingContext, - languageVersionSettings: LanguageVersionSettings - ) { + private fun checkSupportsArrayLiterals(expression: KtCollectionLiteralExpression, context: ExpressionTypingContext) { if (isInsideAnnotationEntryOrClass(expression) && !languageVersionSettings.supportsFeature(LanguageFeature.ArrayLiteralsInAnnotations)) { context.trace.report(UNSUPPORTED_FEATURE.on(expression, LanguageFeature.ArrayLiteralsInAnnotations to languageVersionSettings)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ValueArgumentsToParametersMapper.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ValueArgumentsToParametersMapper.java index cb4ca85f276..6a4928fdeda 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ValueArgumentsToParametersMapper.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ValueArgumentsToParametersMapper.java @@ -87,7 +87,6 @@ public class ValueArgumentsToParametersMapper { private final Map parameterByName; private Map parameterByNameInOverriddenMethods; - private final Set unmappedArguments = Sets.newHashSet(); private final Map varargs = Maps.newHashMap(); private final Set usedParameters = Sets.newHashSet(); private Status status = OK; @@ -164,7 +163,6 @@ public class ValueArgumentsToParametersMapper { } else { report(TOO_MANY_ARGUMENTS.on(argument.asElement(), candidateCall.getCandidateDescriptor())); - unmappedArguments.add(argument); setStatus(WEAK_ERROR); } } @@ -218,7 +216,6 @@ public class ValueArgumentsToParametersMapper { if (nameReference != null) { report(NAMED_PARAMETER_NOT_FOUND.on(nameReference, nameReference)); } - unmappedArguments.add(argument); setStatus(WEAK_ERROR); } else { @@ -229,7 +226,6 @@ public class ValueArgumentsToParametersMapper { if (nameReference != null) { report(ARGUMENT_PASSED_TWICE.on(nameReference)); } - unmappedArguments.add(argument); setStatus(WEAK_ERROR); } else { @@ -244,7 +240,6 @@ public class ValueArgumentsToParametersMapper { public ProcessorState processPositionedArgument(@NotNull ValueArgument argument) { report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(argument.asElement())); setStatus(WEAK_ERROR); - unmappedArguments.add(argument); return positionedThenNamed; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java index 76641551e5d..2f3d27d56cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -16,18 +16,27 @@ package org.jetbrains.kotlin.resolve.calls.tasks; +import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.builtins.FunctionTypesKt; import org.jetbrains.kotlin.descriptors.CallableDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; +import org.jetbrains.kotlin.descriptors.FunctionDescriptor; +import org.jetbrains.kotlin.descriptors.VariableDescriptor; +import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.psi.Call; import org.jetbrains.kotlin.psi.KtReferenceExpression; import org.jetbrains.kotlin.resolve.BindingTrace; +import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject; import org.jetbrains.kotlin.types.ErrorUtils; +import org.jetbrains.kotlin.types.KotlinType; import java.util.Collection; +import java.util.List; import static org.jetbrains.kotlin.diagnostics.Errors.UNRESOLVED_REFERENCE; import static org.jetbrains.kotlin.diagnostics.Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER; @@ -82,6 +91,41 @@ public class TracingStrategyImpl extends AbstractTracingStrategy { @Override public void unresolvedReferenceWrongReceiver(@NotNull BindingTrace trace, @NotNull Collection> candidates) { - trace.report(UNRESOLVED_REFERENCE_WRONG_RECEIVER.on(reference, candidates)); + VariableDescriptor variableDescriptor = isFunctionExpectedError(candidates); + if (variableDescriptor != null) { + trace.report(Errors.FUNCTION_EXPECTED.on(reference, reference, variableDescriptor.getType())); + } + else { + trace.report(UNRESOLVED_REFERENCE_WRONG_RECEIVER.on(reference, candidates)); + } + } + + @Nullable + private static VariableDescriptor isFunctionExpectedError( + @NotNull Collection> candidates + ) { + List variables = CollectionsKt.map(candidates, TracingStrategyImpl::variableIfFunctionExpectedError); + List distinctVariables = CollectionsKt.distinct(variables); + return CollectionsKt.singleOrNull(distinctVariables); + } + + @Nullable + private static VariableDescriptor variableIfFunctionExpectedError( + @NotNull ResolvedCall candidate + ) { + if (!(candidate instanceof VariableAsFunctionResolvedCall)) return null; + + ResolvedCall variableCall = ((VariableAsFunctionResolvedCall) candidate).getVariableCall(); + ResolvedCall functionCall = ((VariableAsFunctionResolvedCall) candidate).getFunctionCall(); + + KotlinType type = variableCall.getCandidateDescriptor().getType(); + + boolean nonFunctionalVar = variableCall.getStatus().isSuccess() && !FunctionTypesKt.isFunctionType(type); + Call functionPsiCall = functionCall.getCall(); + if (nonFunctionalVar && CallResolverUtilKt.isInvokeCallOnVariable(functionPsiCall) && functionPsiCall.getValueArguments().isEmpty()) { + return variableCall.getCandidateDescriptor(); + } + + return null; } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index bdffb2560a6..a29c38538cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -1423,8 +1423,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { public KotlinTypeInfo visitCollectionLiteralExpression( @NotNull KtCollectionLiteralExpression expression, ExpressionTypingContext context ) { - return CollectionLiteralResolver.INSTANCE.resolveCollectionLiteral( - expression, context, components.callResolver, components.builtIns, components.languageVersionSettings); + return components.collectionLiteralResolver.resolveCollectionLiteral(expression, context); } @Override diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingComponents.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingComponents.java index 1b26644adbc..c2fcad22b48 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingComponents.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingComponents.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -62,6 +62,7 @@ public class ExpressionTypingComponents { /*package*/ LanguageVersionSettings languageVersionSettings; /*package*/ Iterable rttiExpressionCheckers; /*package*/ WrappedTypeFactory wrappedTypeFactory; + /*package*/ CollectionLiteralResolver collectionLiteralResolver; @Inject public void setGlobalContext(@NotNull GlobalContext globalContext) { @@ -207,4 +208,9 @@ public class ExpressionTypingComponents { public void setWrappedTypeFactory(WrappedTypeFactory wrappedTypeFactory) { this.wrappedTypeFactory = wrappedTypeFactory; } + + @Inject + public void setCollectionLiteralResolver(CollectionLiteralResolver collectionLiteralResolver) { + this.collectionLiteralResolver = collectionLiteralResolver; + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java index cfdf6af39e3..df5824ff2c0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -108,18 +108,31 @@ public class ExpressionTypingUtils { @NotNull VariableDescriptor variableDescriptor ) { VariableDescriptor oldDescriptor = ScopeUtilsKt.findLocalVariable(scope, variableDescriptor.getName()); + if (oldDescriptor == null) return; - if (oldDescriptor != null && isLocal(variableDescriptor.getContainingDeclaration(), oldDescriptor)) { - PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor); - if (declaration != null) { - if (declaration instanceof KtDestructuringDeclarationEntry && declaration.getParent().getParent() instanceof KtParameter) { - // foo { a, (a, b) -> } -- do not report NAME_SHADOWING on the second 'a', because REDECLARATION must be reported here - PsiElement oldElement = DescriptorToSourceUtils.descriptorToDeclaration(oldDescriptor); + DeclarationDescriptor variableContainingDeclaration = variableDescriptor.getContainingDeclaration(); + if (!isLocal(variableContainingDeclaration, oldDescriptor)) return; - if (oldElement != null && oldElement.getParent().equals(declaration.getParent().getParent().getParent())) return; - } - trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString())); + if (variableDescriptor instanceof ParameterDescriptor) { + if (!isFunctionLiteral(variableContainingDeclaration)) { + return; } + + // parameter of lambda + if (variableContainingDeclaration.getContainingDeclaration() != oldDescriptor.getContainingDeclaration()) { + return; + } + } + + PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor); + if (declaration != null) { + if (declaration instanceof KtDestructuringDeclarationEntry && declaration.getParent().getParent() instanceof KtParameter) { + // foo { a, (a, b) -> } -- do not report NAME_SHADOWING on the second 'a', because REDECLARATION must be reported here + PsiElement oldElement = DescriptorToSourceUtils.descriptorToDeclaration(oldDescriptor); + + if (oldElement != null && oldElement.getParent().equals(declaration.getParent().getParent().getParent())) return; + } + trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString())); } } diff --git a/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt index 5338b94f9f9..2120ea95cdd 100644 --- a/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt +++ b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt @@ -45,8 +45,8 @@ fun foo(y: IntArray) { @Ann1 x + 6 * 2 > 0 @Ann1 x * 6 + 2 > 0 - @Ann1 object { operator fun plus(x: Int) = 1 } + 1 - @Ann1 object { operator fun plus(x: Int) = 1 } + 1 * 4 > 0 + @Ann1 object { operator fun plus(x: Int) = 1 } + 1 + @Ann1 object { operator fun plus(x: Int) = 1 } + 1 * 4 > 0 @Ann1 x foo z + 8 diff --git a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt index fac59fb631f..5713d718dcf 100644 --- a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt +++ b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt @@ -1,4 +1,4 @@ -data class A1(val x: Int, val y: String, val x: Int) { +data class A1(val x: Int, val y: String, val x: Int) { val z = "" } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt index f055c04c69d..638ec1e6117 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt @@ -1,10 +1,10 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED fun test(vararg x1: Int, vararg x2: Int) { - fun test2(vararg x1: Int, vararg x2: Int) { - class LocalClass(vararg x1: Int, vararg x2: Int) { - constructor(vararg x1: Int, vararg x2: Int, xx: Int) {} + fun test2(vararg x1: Int, vararg x2: Int) { + class LocalClass(vararg x1: Int, vararg x2: Int) { + constructor(vararg x1: Int, vararg x2: Int, xx: Int) {} } - fun test3(vararg x1: Int, vararg x2: Int) {} + fun test3(vararg x1: Int, vararg x2: Int) {} } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt index cd90791f233..afcb91126c0 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt @@ -40,7 +40,7 @@ fun bar() { _ checkType { _() } } - foo { `_`, `_` -> + foo { `_`, `_` -> _ checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/implicitIntersection.kt b/compiler/testData/diagnostics/tests/implicitIntersection.kt index dd7dd4cd625..ea537a4f67d 100644 --- a/compiler/testData/diagnostics/tests/implicitIntersection.kt +++ b/compiler/testData/diagnostics/tests/implicitIntersection.kt @@ -22,6 +22,6 @@ fun bar(b: B): String { // Ok: local variable val tmp = if (b is A && b is C) b else null // Error: local function - fun foo(b: B) = if (b is A && b is C) b else null + fun foo(b: B) = if (b is A && b is C) b else null return tmp.toString() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt new file mode 100644 index 00000000000..2b4de189a43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Int.invoke(a: Int) {} +fun Int.invoke(a: Int, b: Int) {} + +class SomeClass + +fun test(identifier: SomeClass, fn: String.() -> Unit) { + identifier() + identifier(123) + identifier(1, 2) + 1.fn() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.txt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.txt new file mode 100644 index 00000000000..0e215f487df --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.txt @@ -0,0 +1,12 @@ +package + +public fun test(/*0*/ identifier: SomeClass, /*1*/ fn: kotlin.String.() -> kotlin.Unit): kotlin.Unit +public fun kotlin.Int.invoke(/*0*/ a: kotlin.Int): kotlin.Unit +public fun kotlin.Int.invoke(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Unit + +public final class SomeClass { + public constructor SomeClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.kt b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.kt new file mode 100644 index 00000000000..1a602f09cc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Int.invoke() {} + +class SomeClass + +fun test(identifier: SomeClass, fn: String.() -> Unit) { + identifier() + identifier(123) + identifier(1, 2) + 1.fn() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.txt b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.txt new file mode 100644 index 00000000000..b5050c0960f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.txt @@ -0,0 +1,11 @@ +package + +public fun test(/*0*/ identifier: SomeClass, /*1*/ fn: kotlin.String.() -> kotlin.Unit): kotlin.Unit +public fun kotlin.Int.invoke(): kotlin.Unit + +public final class SomeClass { + public constructor SomeClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.kt b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.kt new file mode 100644 index 00000000000..bb390470e40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_ANONYMOUS_PARAMETER + +open class Base { + open fun foo(name: String) {} +} + +fun test1(name: String) { + class Local : Base() { + override fun foo(name: String) { + } + } +} + +fun test2(param: String) { + fun local(param: String) {} +} + +fun test3(param: String) { + fun local() { + fff { param -> } + } +} + +fun fff(x: (y: String) -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.txt b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.txt new file mode 100644 index 00000000000..0c33327b0bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.txt @@ -0,0 +1,14 @@ +package + +public fun fff(/*0*/ x: (y: kotlin.String) -> kotlin.Unit): kotlin.Unit +public fun test1(/*0*/ name: kotlin.String): kotlin.Unit +public fun test2(/*0*/ param: kotlin.String): kotlin.Unit +public fun test3(/*0*/ param: kotlin.String): kotlin.Unit + +public open class Base { + public constructor Base() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ name: kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt index b8aa51bb43b..161bf5dab35 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt @@ -15,7 +15,7 @@ fun foo(x: Int, y: String = () .map { definedExternally } - .filter(fun(x: String): Boolean { definedExternally }) + .filter(fun(x: String): Boolean { definedExternally }) definedExternally } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 8814a3ec0ee..882d55b4b56 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -17607,6 +17607,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("functionExpectedWhenSeveralInvokesExist.kt") + public void testFunctionExpectedWhenSeveralInvokesExist() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); + doTest(fileName); + } + @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.kt"); @@ -17697,6 +17703,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("reportFunctionExpectedWhenOneInvokeExist.kt") + public void testReportFunctionExpectedWhenOneInvokeExist() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.kt"); + doTest(fileName); + } + @TestMetadata("valNamedInvoke.kt") public void testValNamedInvoke() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/valNamedInvoke.kt"); @@ -19402,6 +19414,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/shadowing"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("noNameShadowingForSimpleParameters.kt") + public void testNoNameShadowingForSimpleParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.kt"); + doTest(fileName); + } + @TestMetadata("ShadowLambdaParameter.kt") public void testShadowLambdaParameter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.kt"); diff --git a/idea/testData/checker/diagnosticsMessage/instantiationOfInnerClassInQualifiedForm.kt b/idea/testData/checker/diagnosticsMessage/instantiationOfInnerClassInQualifiedForm.kt new file mode 100644 index 00000000000..669df69ed67 --- /dev/null +++ b/idea/testData/checker/diagnosticsMessage/instantiationOfInnerClassInQualifiedForm.kt @@ -0,0 +1,7 @@ +class A { + inner class XYZ + + fun foo() { + val v: A.XYZ = A.XYZ() + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/moveReceiverAnnotation/notExtensionFun.kt b/idea/testData/quickfix/moveReceiverAnnotation/notExtensionFun.kt index 0fee8dbf7ad..70b72279c1e 100644 --- a/idea/testData/quickfix/moveReceiverAnnotation/notExtensionFun.kt +++ b/idea/testData/quickfix/moveReceiverAnnotation/notExtensionFun.kt @@ -1,5 +1,5 @@ // "Move annotation to receiver type" "false" -// ERROR: '@receiver:' annotations could be applied only to extension function or extension property declarations +// ERROR: '@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations // ACTION: Convert to expression body // ACTION: Make internal // ACTION: Make private diff --git a/idea/testData/quickfix/moveReceiverAnnotation/notExtensionVal.kt b/idea/testData/quickfix/moveReceiverAnnotation/notExtensionVal.kt index 2143b19947b..a5acb4bc298 100644 --- a/idea/testData/quickfix/moveReceiverAnnotation/notExtensionVal.kt +++ b/idea/testData/quickfix/moveReceiverAnnotation/notExtensionVal.kt @@ -1,5 +1,5 @@ // "Move annotation to receiver type" "false" -// ERROR: '@receiver:' annotations could be applied only to extension function or extension property declarations +// ERROR: '@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations // ACTION: Make internal // ACTION: Make private // ACTION: Specify type explicitly diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java index ca1b86f5dce..ae41edef17a 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java @@ -992,6 +992,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest { doTest(fileName); } + @TestMetadata("instantiationOfInnerClassInQualifiedForm.kt") + public void testInstantiationOfInnerClassInQualifiedForm() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/instantiationOfInnerClassInQualifiedForm.kt"); + doTest(fileName); + } + @TestMetadata("noSubstitutedTypeParameter.kt") public void testNoSubstitutedTypeParameter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/noSubstitutedTypeParameter.kt");