diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 316e25e0633..9d30768dedb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -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. @@ -51,6 +51,7 @@ import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations @@ -375,6 +376,10 @@ class FunctionDescriptorResolver( val valueParameterDescriptor = descriptorResolver.resolveValueParameterDescriptor(parameterScope, functionDescriptor, valueParameter, i, type, trace) + + // Do not report NAME_SHADOWING for lambda destructured parameters as they may be not fully resolved at this time + ExpressionTypingUtils.checkVariableShadowing(parameterScope, trace, valueParameterDescriptor) + parameterScope.addVariableDescriptor(valueParameterDescriptor) result.add(valueParameterDescriptor) } diff --git a/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt index 49a13881b87..5338b94f9f9 100644 --- a/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt +++ b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.kt @@ -30,8 +30,8 @@ fun foo(y: IntArray) { @Ann1 y[0] - @Ann1 { x: Int -> x } - @Ann1 { x: Int -> x }(1) + @Ann1 { x: Int -> x } + @Ann1 { x: Int -> x }(1) @Ann1 object { fun foo() = 1 } @Ann1 object { fun foo() = 1 }.foo() @@ -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/annotations/options/targets/funtypeargs.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt index e73805383bf..bf63064be24 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt @@ -9,5 +9,5 @@ fun transform(i: Int, tr: (@special Int) -> Int): fun foo(i: Int): Int { val j = @special i + 1 if (j == 1) return foo(@special 42) - return transform(@special j, @special { i: @base Int -> @base i * 2 }) + return transform(@special j, @special { i: @base Int -> @base i * 2 }) } diff --git a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt index 5713d718dcf..fac59fb631f 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 18cb39641c0..f055c04c69d 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 test3(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 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 afcb91126c0..cd90791f233 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 ea537a4f67d..dd7dd4cd625 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/inline/kt4869.kt b/compiler/testData/diagnostics/tests/inline/kt4869.kt index 9c353f4e130..33527181766 100644 --- a/compiler/testData/diagnostics/tests/inline/kt4869.kt +++ b/compiler/testData/diagnostics/tests/inline/kt4869.kt @@ -1,5 +1,5 @@ inline fun foo(f: () -> Unit) { - val ff = { f: () -> Unit -> + val ff = { f: () -> Unit -> f.invoke() } ff(f) diff --git a/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt b/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt index 7ebe2dacaa1..01a8f78943e 100644 --- a/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt +++ b/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt @@ -37,6 +37,6 @@ fun test(b: B) { b.foo(Number::foobar) b.baz { - b -> b checkType { _>() } + b -> b checkType { _>() } } } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.kt new file mode 100644 index 00000000000..0bcb8f31de6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo1(i: (Int) -> Unit) {} +fun foo2(i: (Int, Int) -> Unit) {} +fun foo3(i: (Pair) -> Unit) {} + +fun bar(x: Int, y: Int) { + foo1 { x -> x } + foo2 { x: Int, y: Int -> x + y } + foo3 { (x, y) -> x + y } +} + +data class Pair(val a: Int, val b: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.txt b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.txt new file mode 100644 index 00000000000..c21ed00fe0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.txt @@ -0,0 +1,18 @@ +package + +public fun bar(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int): kotlin.Unit +public fun foo1(/*0*/ i: (kotlin.Int) -> kotlin.Unit): kotlin.Unit +public fun foo2(/*0*/ i: (kotlin.Int, kotlin.Int) -> kotlin.Unit): kotlin.Unit +public fun foo3(/*0*/ i: (Pair) -> kotlin.Unit): kotlin.Unit + +public final data class Pair { + public constructor Pair(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int) + public final val a: kotlin.Int + public final val b: kotlin.Int + public final operator /*synthesized*/ fun component1(): kotlin.Int + public final operator /*synthesized*/ fun component2(): kotlin.Int + public final /*synthesized*/ fun copy(/*0*/ a: kotlin.Int = ..., /*1*/ b: kotlin.Int = ...): Pair + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.kt index f015847d3e6..bc3cbfdf0f8 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.kt +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.kt @@ -1,5 +1,5 @@ fun ff(): Int { var i = 1 - { i: Int -> i } + { i: Int -> i } return i } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt index 161bf5dab35..b8aa51bb43b 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/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt index 089e83bf94a..c66e84f7f6f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt @@ -44,7 +44,7 @@ fun foo() { manyArgumentsBuilder({}, { "" }, { 1 }) manyArgumentsBuilder({}, { 1 }, { 2 }) - severalParamsInLambda { x, y -> + severalParamsInLambda { x, y -> x checkType { _() } y checkType { _() } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index a9c960b9c11..eb59d9251d4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19174,6 +19174,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/shadowing"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("ShadowLambdaParameter.kt") + public void testShadowLambdaParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.kt"); + doTest(fileName); + } + @TestMetadata("ShadowMultiDeclarationWithFunParameter.kt") public void testShadowMultiDeclarationWithFunParameter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/shadowing/ShadowMultiDeclarationWithFunParameter.kt");