Resolve local function parameters with function inner scope
This allows to use type parameters and value paramters in default value expressions #KT-7984 Fixed #KT-7985 Fixed
This commit is contained in:
+2
-2
@@ -101,18 +101,18 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
|||||||
// Necessary for local functions
|
// Necessary for local functions
|
||||||
ForceResolveUtil.forceResolveAllContents(functionDescriptor.annotations)
|
ForceResolveUtil.forceResolveAllContents(functionDescriptor.annotations)
|
||||||
|
|
||||||
|
val functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace, components.overloadChecker)
|
||||||
if (!function.hasDeclaredReturnType() && !function.hasBlockBody()) {
|
if (!function.hasDeclaredReturnType() && !function.hasBlockBody()) {
|
||||||
ForceResolveUtil.forceResolveAllContents(functionDescriptor.returnType)
|
ForceResolveUtil.forceResolveAllContents(functionDescriptor.returnType)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace, components.overloadChecker)
|
|
||||||
components.expressionTypingServices.checkFunctionReturnType(
|
components.expressionTypingServices.checkFunctionReturnType(
|
||||||
functionInnerScope, function, functionDescriptor, context.dataFlowInfo, null, context.trace
|
functionInnerScope, function, functionDescriptor, context.dataFlowInfo, null, context.trace
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
components.valueParameterResolver.resolveValueParameters(
|
components.valueParameterResolver.resolveValueParameters(
|
||||||
function.valueParameters, functionDescriptor.valueParameters, context.scope, context.dataFlowInfo, context.trace
|
function.valueParameters, functionDescriptor.valueParameters, functionInnerScope, context.dataFlowInfo, context.trace
|
||||||
)
|
)
|
||||||
|
|
||||||
components.modifiersChecker.withTrace(context.trace).checkModifiersForLocalDeclaration(function, functionDescriptor)
|
components.modifiersChecker.withTrace(context.trace).checkModifiersForLocalDeclaration(function, functionDescriptor)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fun foo(): String {
|
||||||
|
fun bar(x: String, y: String = x): String {
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
|
||||||
|
return bar("OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return foo()
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
fun bar(x: String, y: String = x) {}
|
||||||
|
fun baz(x: Int = <!UNINITIALIZED_PARAMETER!>y<!>, y: Int) {}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
fun <T> bar(x: List<T> = listOf<T>()) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> listOf(): List<T> = TODO()
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
public fun </*0*/ T> listOf(): kotlin.collections.List<T>
|
||||||
+15
@@ -10398,6 +10398,21 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/localFunctions")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class LocalFunctions extends AbstractIrBlackBoxCodegenTest {
|
||||||
|
public void testAllFilesPresentInLocalFunctions() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/localFunctions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterAsDefaultValue.kt")
|
||||||
|
public void testParameterAsDefaultValue() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localFunctions/parameterAsDefaultValue.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/mangling")
|
@TestMetadata("compiler/testData/codegen/box/mangling")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -17164,6 +17164,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterAsDefaultValueInLocalFunction.kt")
|
||||||
|
public void testParameterAsDefaultValueInLocalFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/parameterAsDefaultValueInLocalFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("resolveAnnotatedLambdaArgument.kt")
|
@TestMetadata("resolveAnnotatedLambdaArgument.kt")
|
||||||
public void testResolveAnnotatedLambdaArgument() throws Exception {
|
public void testResolveAnnotatedLambdaArgument() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt");
|
||||||
@@ -17218,6 +17224,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameterInDefaultValueInLocalFunction.kt")
|
||||||
|
public void testTypeParameterInDefaultValueInLocalFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("wrongNumberOfTypeArguments.kt")
|
@TestMetadata("wrongNumberOfTypeArguments.kt")
|
||||||
public void testWrongNumberOfTypeArguments() throws Exception {
|
public void testWrongNumberOfTypeArguments() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.kt");
|
||||||
|
|||||||
@@ -10398,6 +10398,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/localFunctions")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class LocalFunctions extends AbstractBlackBoxCodegenTest {
|
||||||
|
public void testAllFilesPresentInLocalFunctions() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/localFunctions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterAsDefaultValue.kt")
|
||||||
|
public void testParameterAsDefaultValue() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localFunctions/parameterAsDefaultValue.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/mangling")
|
@TestMetadata("compiler/testData/codegen/box/mangling")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -10398,6 +10398,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/localFunctions")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class LocalFunctions extends AbstractLightAnalysisModeTest {
|
||||||
|
public void testAllFilesPresentInLocalFunctions() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/localFunctions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterAsDefaultValue.kt")
|
||||||
|
public void testParameterAsDefaultValue() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localFunctions/parameterAsDefaultValue.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/mangling")
|
@TestMetadata("compiler/testData/codegen/box/mangling")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// PARAM_TYPES: kotlin.Int
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in bar.foo
|
||||||
fun bar(n: Int) {
|
fun bar(n: Int) {
|
||||||
fun foo(a: Int, b: Int = <selection>a + n</selection>) = a + b - n - 1
|
fun foo(a: Int, b: Int = <selection>a + n</selection>) = a + b - n - 1
|
||||||
}
|
}
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in bar.foo
|
||||||
|
fun bar(n: Int) {
|
||||||
|
fun i(a: Int) = a + n
|
||||||
|
|
||||||
|
fun foo(a: Int, b: Int = i(a)) = a + b - n - 1
|
||||||
|
}
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
Cannot generate function with erroneous return type
|
|
||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// PARAM_TYPES: kotlin.Int
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in bar.foo
|
||||||
fun bar(n: Int) {
|
fun bar(n: Int) {
|
||||||
fun foo(a: Int, b: Int = { <selection>a + n</selection> }.invoke()) = a + b - n - 1
|
fun foo(a: Int, b: Int = { <selection>a + n</selection> }.invoke()) = a + b - n - 1
|
||||||
}
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in bar.foo
|
||||||
|
fun bar(n: Int) {
|
||||||
|
fun i(a: Int) = a + n
|
||||||
|
|
||||||
|
fun foo(a: Int, b: Int = { i(a) }.invoke()) = a + b - n - 1
|
||||||
|
}
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
Cannot generate function with erroneous return type
|
|
||||||
+15
@@ -11941,6 +11941,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/localFunctions")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class LocalFunctions extends AbstractJsCodegenBoxTest {
|
||||||
|
public void testAllFilesPresentInLocalFunctions() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/localFunctions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterAsDefaultValue.kt")
|
||||||
|
public void testParameterAsDefaultValue() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localFunctions/parameterAsDefaultValue.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/mangling")
|
@TestMetadata("compiler/testData/codegen/box/mangling")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user