From b178c795732834aa745e3aabbf4517f79d919722 Mon Sep 17 00:00:00 2001 From: svtk Date: Tue, 26 Nov 2013 17:42:39 +0400 Subject: [PATCH] analyze function arguments after completion for unresolved and ambiguity cases --- .../jet/lang/resolve/calls/CallResolver.java | 6 ++--- .../funcLiteralArgsInsideAmbiguity.kt | 14 ++++++++++ .../PropertyAndFunctionNameClash.resolve | 26 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 ++++ .../jet/resolve/JetResolveTestGenerated.java | 5 ++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt create mode 100644 compiler/testData/resolve/PropertyAndFunctionNameClash.resolve diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index c89a5d64fdc..96b9ad1d740 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -31,7 +31,6 @@ import org.jetbrains.jet.lang.resolve.calls.context.*; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl; 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.ResolutionDebugInfo; @@ -60,8 +59,8 @@ import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_ import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.resolve.BindingContext.NON_DEFAULT_EXPRESSION_DATA_FLOW; import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLUTION_SCOPE; -import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL; import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS; +import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS; import static org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults.Code.*; import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; @@ -324,6 +323,7 @@ public class CallResolver { results.getResultingCall().markCallAsCompleted(); } else { + argumentTypeResolver.checkTypesForFunctionArgumentsWithNoCallee(context); candidateResolver.completeNestedCallsForNotResolvedInvocation(context); } } @@ -475,7 +475,7 @@ public class CallResolver { } else { context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference)); - argumentTypeResolver.checkTypesWithNoCallee(context, RESOLVE_FUNCTION_ARGUMENTS); + argumentTypeResolver.checkTypesWithNoCallee(context, SHAPE_FUNCTION_ARGUMENTS); } return resultsForFirstNonemptyCandidateSet != null ? resultsForFirstNonemptyCandidateSet : OverloadResolutionResultsImpl.nameNotFound(); } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt new file mode 100644 index 00000000000..b5a286c1d30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +package d + +fun bar() { + val i: Int? = 42 + if (i != null) { + doSmth1 { + val x = i + 1 + } +} +} + +fun doSmth1(f: ()->Unit) {} +fun doSmth1(g: (Int)->Unit) {} \ No newline at end of file diff --git a/compiler/testData/resolve/PropertyAndFunctionNameClash.resolve b/compiler/testData/resolve/PropertyAndFunctionNameClash.resolve new file mode 100644 index 00000000000..9dee49d1649 --- /dev/null +++ b/compiler/testData/resolve/PropertyAndFunctionNameClash.resolve @@ -0,0 +1,26 @@ +open class HtmlTag + +trait NavigationBuilder { + public var text: ((String) -> String)? + ~in_NB~var inNavigationBuilder: Int +} + +fun HtmlTag.navigation(body: NavigationBuilder.() -> Unit) { +} +fun HtmlTag.a(contents: A.() -> Unit) { +} + +trait A : HtmlTag { + ~text_in_A~var text: String + ~in_A~var inA: Int +} + +fun HtmlTag.test(a: String) { + navigation { + a { + `text_in_A`text = "1" + `in_NB`inNavigationBuilder = 1 + `in_A`inA = 2 + } + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index e2a05401656..f986037fc39 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -4178,6 +4178,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/AssertNotNull.kt"); } + @TestMetadata("funcLiteralArgsInsideAmbiguity.kt") + public void testFuncLiteralArgsInsideAmbiguity() throws Exception { + doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideAmbiguity.kt"); + } + @TestMetadata("funcLiteralArgsInsideUnresolvedFunction.kt") public void testFuncLiteralArgsInsideUnresolvedFunction() throws Exception { doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/funcLiteralArgsInsideUnresolvedFunction.kt"); diff --git a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTestGenerated.java b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTestGenerated.java index 89011fe322e..ca2a4c6efdb 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTestGenerated.java @@ -117,6 +117,11 @@ public class JetResolveTestGenerated extends AbstractResolveTest { doTest("compiler/testData/resolve/Projections.resolve"); } + @TestMetadata("PropertyAndFunctionNameClash.resolve") + public void testPropertyAndFunctionNameClash() throws Exception { + doTest("compiler/testData/resolve/PropertyAndFunctionNameClash.resolve"); + } + @TestMetadata("ResolveOfInfixExpressions.resolve") public void testResolveOfInfixExpressions() throws Exception { doTest("compiler/testData/resolve/ResolveOfInfixExpressions.resolve");