From 8baa9ba1deaabaab09dd75f02929f5602ac11539 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 22 Sep 2016 14:42:23 +0300 Subject: [PATCH] No parameter names in type of lambda expression and anonymous function --- .../types/expressions/FunctionsTypingVisitor.kt | 17 ++++------------- .../basic/UsageInFunctionLiteral.values | 4 ++-- .../lexicalScopes/functionLiteralScope.values | 10 +++++----- .../functions/functionAsExpression.values | 4 ++-- .../tests/FunctionParameterWithoutType.txt | 2 +- .../tests/annotations/onFunctionParameter.txt | 2 +- .../tests/functionAsExpression/Parameters.txt | 8 ++++---- .../functionAsExpression/ReturnTypeCheck.txt | 2 +- .../WithGenericParameters.txt | 6 +++--- .../functionAsExpression/WithOuterGeneric.txt | 4 ++-- .../tests/functionLiterals/DeprecatedSyntax.txt | 10 +++++----- .../return/LambdaWithParameter.txt | 2 +- .../tests/functionLiterals/return/SmartCast.txt | 2 +- .../diagnostics/tests/regressions/kt398.txt | 2 +- .../extFunctionTypeAsUpperBound.txt | 2 +- .../typeParameters/functionTypeAsUpperBound.txt | 2 +- .../diagnosticMessage/functionPlaceholder3.html | 2 +- .../functionCall/FunctionalValue2.kt | 2 +- 18 files changed, 37 insertions(+), 46 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 5425bab7cc7..843df03f361 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.diagnostics.DiagnosticUtils import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors.* -import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries import org.jetbrains.kotlin.resolve.* @@ -123,25 +122,17 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre return createTypeInfo(components.dataFlowAnalyzer.checkStatementType(function, context), context) } else { - return components.dataFlowAnalyzer.createCheckedTypeInfo(functionDescriptor.createFunctionType(context), context, function) + return components.dataFlowAnalyzer.createCheckedTypeInfo(functionDescriptor.createFunctionType(), context, function) } } - private fun SimpleFunctionDescriptor.createFunctionType(context: ExpressionTypingContext): KotlinType? { - val bindingContext = context.trace.bindingContext - val parameterNames = valueParameters.map { - // do not include auto-created 'it' into the type signature - if (bindingContext[BindingContext.AUTO_CREATED_IT, it] != true) - it.name - else - SpecialNames.NO_NAME_PROVIDED - } + private fun SimpleFunctionDescriptor.createFunctionType(): KotlinType? { return createFunctionType( components.builtIns, Annotations.EMPTY, extensionReceiverParameter?.type, valueParameters.map { it.type }, - parameterNames, + null, returnType ?: return null ) } @@ -160,7 +151,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre val safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected) functionDescriptor.setReturnType(safeReturnType) - val resultType = functionDescriptor.createFunctionType(context)!! + val resultType = functionDescriptor.createFunctionType()!! if (functionTypeExpected) { // all checks were done before return createTypeInfo(resultType, context) diff --git a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values index 797aa09ea5f..9998d68a207 100644 --- a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values +++ b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values @@ -7,8 +7,8 @@ fun foo() { } } --------------------- -1 : Int NEW: r(1) -> -{ x: Int -> val y = x + a use(a) } : {<: (x: Int) -> Array} NEW: r({ x: Int -> val y = x + a use(a) }) -> +1 : Int NEW: r(1) -> +{ x: Int -> val y = x + a use(a) } : {<: (Int) -> Array} NEW: r({ x: Int -> val y = x + a use(a) }) -> ===================== == anonymous_0 == { x: Int -> diff --git a/compiler/testData/cfg-variables/lexicalScopes/functionLiteralScope.values b/compiler/testData/cfg-variables/lexicalScopes/functionLiteralScope.values index 5f8b48f3aed..a60a459215d 100644 --- a/compiler/testData/cfg-variables/lexicalScopes/functionLiteralScope.values +++ b/compiler/testData/cfg-variables/lexicalScopes/functionLiteralScope.values @@ -8,11 +8,11 @@ fun foo() { "after" } --------------------- -"before" : * NEW: r("before") -> -1 : Int NEW: r(1) -> -{ x: Int -> val a = x + b } : {<: (x: Int) -> Unit} NEW: r({ x: Int -> val a = x + b }) -> -"after" : * NEW: r("after") -> -{ "before" val b = 1 val f = { x: Int -> val a = x + b } "after" } : * COPY +"before" : * NEW: r("before") -> +1 : Int NEW: r(1) -> +{ x: Int -> val a = x + b } : {<: (Int) -> Unit} NEW: r({ x: Int -> val a = x + b }) -> +"after" : * NEW: r("after") -> +{ "before" val b = 1 val f = { x: Int -> val a = x + b } "after" } : * COPY ===================== == anonymous_0 == { x: Int -> diff --git a/compiler/testData/cfg/declarations/functions/functionAsExpression.values b/compiler/testData/cfg/declarations/functions/functionAsExpression.values index 96640646e67..e3a5cf484ea 100644 --- a/compiler/testData/cfg/declarations/functions/functionAsExpression.values +++ b/compiler/testData/cfg/declarations/functions/functionAsExpression.values @@ -4,8 +4,8 @@ fun test() { val g = fun foo(n: Int) = 2 } --------------------- -fun(n: Int): Int { return 1 } : {<: (n: Int) -> Int} NEW: r(fun(n: Int): Int { return 1 }) -> -fun foo(n: Int) = 2 : {<: (n: Int) -> Int} NEW: r(fun foo(n: Int) = 2) -> +fun(n: Int): Int { return 1 } : {<: (Int) -> Int} NEW: r(fun(n: Int): Int { return 1 }) -> +fun foo(n: Int) = 2 : {<: (Int) -> Int} NEW: r(fun foo(n: Int) = 2) -> ===================== == anonymous_0 == fun(n: Int): Int { return 1 } diff --git a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.txt b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.txt index 5221f303765..524047d4560 100644 --- a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.txt +++ b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.txt @@ -2,7 +2,7 @@ package public val bar: (???) -> kotlin.Unit public val la: (???) -> kotlin.Unit -public val las: (a: kotlin.Int) -> kotlin.Unit +public val las: (kotlin.Int) -> kotlin.Unit public fun test(/*0*/ a: [ERROR : Type annotation was missing for parameter a]): kotlin.Unit public final class A { diff --git a/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.txt b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.txt index 0f431a61686..b45c8e56e43 100644 --- a/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.txt +++ b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.txt @@ -1,6 +1,6 @@ package -public val bar: (g: kotlin.Int) -> kotlin.Unit +public val bar: (kotlin.Int) -> kotlin.Unit public fun test(/*0*/ @ann() p: kotlin.Int): kotlin.Unit public final annotation class ann : kotlin.Annotation { diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.txt b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.txt index 54974ab1e59..555163912eb 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.txt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.txt @@ -1,7 +1,7 @@ package -public val bar: (p: kotlin.Int) -> kotlin.Unit -public val bas: (p: kotlin.IntArray) -> kotlin.Unit -public fun gar(): (p: kotlin.Int) -> kotlin.Unit -public fun gas(): (p: kotlin.IntArray) -> kotlin.Unit +public val bar: (kotlin.Int) -> kotlin.Unit +public val bas: (kotlin.IntArray) -> kotlin.Unit +public fun gar(): (kotlin.Int) -> kotlin.Unit +public fun gas(): (kotlin.IntArray) -> kotlin.Unit public fun outer(/*0*/ b: kotlin.Any?): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.txt b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.txt index 260bc048f79..78734d6b2cc 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.txt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.txt @@ -1,3 +1,3 @@ package -public val foo: (a: kotlin.Int) -> kotlin.String +public val foo: (kotlin.Int) -> kotlin.String diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.txt b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.txt index bb8bb81cedd..fb81702471f 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.txt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.txt @@ -1,9 +1,9 @@ package -public val extension_generic_fun: T.(t: T) -> T -public val generic_fun: (t: T) -> T +public val extension_generic_fun: T.(T) -> T +public val generic_fun: (T) -> T public fun devNull(/*0*/ a: kotlin.Any?): kotlin.Unit -public fun fun_with_where(): T.(t: T) -> T +public fun fun_with_where(): T.(T) -> T public fun outer(): kotlin.Unit public interface A { diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.txt b/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.txt index bcf3efc1264..a50c552e344 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.txt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.txt @@ -3,7 +3,7 @@ package public val T.fromVal: () -> T public fun devNull(/*0*/ a: kotlin.Any?): kotlin.Unit public fun outer(): kotlin.Unit -public fun parameter(): (t: T) -> T +public fun parameter(): (T) -> T public fun receiver(): T.() -> T public fun returnType(): () -> T @@ -11,7 +11,7 @@ public final class Outer { public constructor Outer() 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 final fun parameter(): (t: T) -> T + public final fun parameter(): (T) -> T public final fun receiver(): T.() -> T public final fun returnType(): () -> T public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.txt b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.txt index 2364735997c..b0974b42778 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.txt +++ b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.txt @@ -1,12 +1,12 @@ package -public val newSyntax: (a: kotlin.Int) -> kotlin.Unit +public val newSyntax: (kotlin.Int) -> kotlin.Unit public val newSyntax1: (???, ???) -> kotlin.Unit -public val newSyntax2: (a: kotlin.Int, b: kotlin.Int) -> kotlin.Unit -public val newSyntax3: (???, b: kotlin.Int) -> kotlin.Unit -public val newSyntax4: (a: kotlin.Int, ???) -> kotlin.Unit +public val newSyntax2: (kotlin.Int, kotlin.Int) -> kotlin.Unit +public val newSyntax3: (???, kotlin.Int) -> kotlin.Unit +public val newSyntax4: (kotlin.Int, ???) -> kotlin.Unit public val none: () -> kotlin.Unit -public val parameterWithFunctionType: (a: ((kotlin.Int) -> kotlin.Int) -> [ERROR : No type element]) -> kotlin.Unit +public val parameterWithFunctionType: (((kotlin.Int) -> kotlin.Int) -> [ERROR : No type element]) -> kotlin.Unit public val parenthesizedParameters: (???) -> kotlin.Unit public val parenthesizedParameters2: (???) -> kotlin.Unit public val receiver: () -> ??? diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.txt b/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.txt index 741450b1eb8..93007d9a393 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.txt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.txt @@ -1,6 +1,6 @@ package -public val a: (i: kotlin.Int) -> kotlin.String +public val a: (kotlin.Int) -> kotlin.String public val b: kotlin.String public val flag: kotlin.Boolean = true public fun foo(/*0*/ f: (kotlin.Int) -> T): T diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.txt b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.txt index 5e742f13e4f..b949bc46d3e 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.txt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.txt @@ -1,6 +1,6 @@ package -public val a: (it: kotlin.Int?) -> kotlin.Int? +public val a: (kotlin.Int?) -> kotlin.Int? public val b: kotlin.Int? public val c: kotlin.Int public fun let(/*0*/ f: (kotlin.Int?) -> R): R diff --git a/compiler/testData/diagnostics/tests/regressions/kt398.txt b/compiler/testData/diagnostics/tests/regressions/kt398.txt index a0647250fbc..2bedb075e16 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt398.txt +++ b/compiler/testData/diagnostics/tests/regressions/kt398.txt @@ -4,7 +4,7 @@ public fun box(): kotlin.String public final class X { public constructor X() - public final val check: (a: kotlin.Any) -> kotlin.Boolean + public final val check: (kotlin.Any) -> kotlin.Boolean 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/typeParameters/extFunctionTypeAsUpperBound.txt b/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.txt index dc7b03c48bb..126d6bad704 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.txt +++ b/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.txt @@ -1,6 +1,6 @@ package -public val kotlin.String> bar: (x: kotlin.Int) -> kotlin.String +public val kotlin.String> bar: (kotlin.Int) -> kotlin.String public fun kotlin.String> foo(): kotlin.Unit public final class A kotlin.Unit> { diff --git a/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.txt b/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.txt index 9a36eeb9e54..7245929a337 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.txt +++ b/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.txt @@ -1,6 +1,6 @@ package -public val kotlin.String> bar: (x: kotlin.Int) -> kotlin.String +public val kotlin.String> bar: (kotlin.Int) -> kotlin.String public fun kotlin.String> foo(): kotlin.Unit public final class A kotlin.Unit, /*1*/ U : (kotlin.Int) -> kotlin.Double, /*2*/ V : (T, U) -> U> { diff --git a/idea/testData/diagnosticMessage/functionPlaceholder3.html b/idea/testData/diagnosticMessage/functionPlaceholder3.html index 1a00945dded..74dccbbc138 100644 --- a/idea/testData/diagnosticMessage/functionPlaceholder3.html +++ b/idea/testData/diagnosticMessage/functionPlaceholder3.html @@ -18,7 +18,7 @@ Type inference failed: ( - (x: Int) → Int + (Int) → Int ) diff --git a/idea/testData/parameterInfo/functionCall/FunctionalValue2.kt b/idea/testData/parameterInfo/functionCall/FunctionalValue2.kt index f5f7f8958b5..c75d1c2fff7 100644 --- a/idea/testData/parameterInfo/functionCall/FunctionalValue2.kt +++ b/idea/testData/parameterInfo/functionCall/FunctionalValue2.kt @@ -6,6 +6,6 @@ fun call() { } /* +Text: (String, String), Disabled: false, Strikeout: false, Green: true Text: (name: String, value: Int), Disabled: false, Strikeout: false, Green: false -Text: (s: String, s1: String), Disabled: false, Strikeout: false, Green: true */